
/* ─── RESET & BASE ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d0d0f;
  --surface:   #161618;
  --surface2:  #1e1e21;
  --border:    rgba(255,255,255,0.07);
  --border2:   rgba(255,255,255,0.12);
  --text:      #f0f0f2;
  --muted:     #7a7a8a;
  --faint:     #3a3a45;
  --orange:    #FF8C42;
  --orange2:   #ff6b1a;
  --green:     #00e5a0;
  --blue:      #4285f4;
  --sidebar-w: 220px;
  --chat-max:  780px;
  --sidebar-collapsed-w: 0px;
}

html, body { height: 100%; }

/* ─── LIGHT THEME ───────────────────────────────────────────────────── */
body.light {
  --bg:      #f4f4f6;
  --surface: #ffffff;
  --surface2:#f0f0f4;
  --border:  rgba(0,0,0,0.08);
  --border2: rgba(0,0,0,0.14);
  --text:    #18181c;
  --muted:   #666677;
  --faint:   #ccccd8;
}
body.light .sidebar { background: rgba(240,240,246,0.98); }
body.light .topbar  { background: #ffffff; }
body.light .bubble.message.ai .bubble { background: #f0f0f4; }
body.light .message.ai .bubble { background: #f0f0f4; border-color: rgba(0,0,0,0.08); color: #18181c; }
body.light #chat-input { color: #18181c; }
body.light .input-wrapper { background: #fff; }
body.light .sb-chat-title { color: #333344; }
body.light .sb-project-name { color: #333344; }

/* ─── THEME TOGGLE BTN ──────────────────────────────────────────────── */
.theme-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  transition: all .15s;
  flex-shrink: 0;
}
.theme-btn:hover { color: var(--text); border-color: var(--orange); }

/* ─── MESSAGE ACTION BUTTONS (rigenera, copia, modifica, TTS) ───────── */
.msg-actions {
  display: none;
  gap: 4px;
  margin-top: 4px;
  flex-wrap: wrap;
}
.message:hover .msg-actions,
.message.editing .msg-actions { display: flex; }
.msg-action-btn {
  display: flex; align-items: center; gap: 4px;
  padding: 3px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 11px; font-weight: 500;
  cursor: pointer;
  transition: all .12s;
  font-family: 'Space Grotesk', sans-serif;
  white-space: nowrap;
}
.msg-action-btn:hover { color: var(--text); border-color: var(--border2); background: var(--surface); }
.msg-action-btn.active { color: var(--orange); border-color: var(--orange); }

/* ── Anteprima inline automatica (richiesta 2026-10-01) ─────────────── */
.inline-preview-wrap {
  margin: 6px 0 2px;
  border: 1px solid var(--border2);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface2);
  max-width: 560px;
}
.inline-preview-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 10px;
  font-size: 11px; font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  font-family: 'Space Grotesk', sans-serif;
}
.inline-preview-toggle {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  color: var(--muted); font-size: 11px; font-weight: 500;
  padding: 2px 7px; cursor: pointer; transition: all .12s;
  font-family: 'Space Grotesk', sans-serif;
}
.inline-preview-toggle:hover { color: var(--text); border-color: var(--border2); }
.inline-preview-frame {
  display: block;
  width: 100%;
  height: 220px;
  border: 0;
  background: #fff;
  transition: height .2s ease;
}
.inline-preview-frame.expanded { height: 520px; }
.msg-action-btn.tts-playing { color: var(--green); border-color: var(--green); animation: recPulse 1.5s infinite; }
.msg-action-btn.preview-open-btn { color: var(--orange); border-color: var(--orange); background: rgba(232,101,10,.08); }
.msg-action-btn.preview-open-btn:hover { background: var(--orange); color: #fff; }

/* ─── EDIT MESSAGE INLINE ───────────────────────────────────────────── */
.edit-textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--orange);
  border-radius: 10px;
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 13px;
  padding: 8px 12px;
  outline: none;
  resize: none;
  min-height: 48px;
  max-height: 160px;
  overflow-y: auto;
  box-shadow: 0 0 0 3px rgba(255,140,66,0.1);
}
.edit-actions {
  display: flex; gap: 6px; margin-top: 6px;
}
.edit-confirm-btn {
  padding: 5px 14px; border-radius: 7px; border: none;
  background: var(--orange); color: #fff;
  font-family: 'Space Grotesk', sans-serif; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: opacity .15s;
}
.edit-confirm-btn:hover { opacity: .85; }
.edit-cancel-btn {
  padding: 5px 12px; border-radius: 7px; border: none;
  background: var(--surface2); color: var(--muted);
  font-family: 'Space Grotesk', sans-serif; font-size: 12px;
  cursor: pointer;
}

/* ─── EXPORT CHAT BTN ───────────────────────────────────────────────── */
.export-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--muted);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 12px; font-weight: 500;
  cursor: pointer; transition: all .15s;
  white-space: nowrap;
}
.export-btn:hover { color: var(--text); border-color: var(--orange); }

/* ─── MEMORIA UTENTE modal ──────────────────────────────────────────── */
.memory-modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 9200;
  background: rgba(0,0,0,.7); backdrop-filter: blur(5px);
  align-items: center; justify-content: center;
}
.memory-modal-overlay.open { display: flex; }
.memory-modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 18px;
  padding: 26px 24px 22px;
  width: min(480px, 94vw);
  display: flex; flex-direction: column; gap: 14px;
  animation: modalIn .22s ease;
  position: relative;
}
.memory-modal h4 { font-size: 16px; font-weight: 700; color: var(--text); }
.memory-modal p  { font-size: 13px; color: var(--muted); line-height: 1.5; }
.memory-modal textarea {
  width: 100%; min-height: 120px;
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 10px; color: var(--text);
  font-family: 'Space Grotesk', sans-serif; font-size: 13px;
  padding: 10px 13px; outline: none; resize: vertical;
  transition: border-color .15s;
}
.memory-modal textarea:focus { border-color: var(--orange); }

/* ─── KEYBOARD SHORTCUTS HINT ───────────────────────────────────────── */
.kbd {
  display: inline-block;
  padding: 1px 5px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 4px;
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: var(--muted);
}

/* ─── MOBILE DRAWER (sidebar as overlay on mobile) ─────────────────── */
.mobile-menu-btn {
  display: none;
  width: 36px; height: 36px;
  border-radius: 9px;
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--muted);
  align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: all .15s;
}
.mobile-menu-btn:hover { color: var(--text); }

.drawer-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(2px);
}
.drawer-overlay.open { display: block; }

/* ─── KEYBOARD SHORTCUTS PANEL ──────────────────────────────────────── */
.shortcuts-panel {
  display: none; position: fixed; inset: 0; z-index: 9300;
  background: rgba(0,0,0,.7); backdrop-filter: blur(5px);
  align-items: center; justify-content: center;
}
.shortcuts-panel.open { display: flex; }
.shortcuts-box {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 18px;
  padding: 26px 28px 22px;
  width: min(420px, 94vw);
  animation: modalIn .22s ease;
}
.shortcuts-box h4 { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 16px; }
.shortcut-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 0; border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--muted);
}
.shortcut-row:last-child { border-bottom: none; }
.shortcut-keys { display: flex; gap: 4px; }

body {
  font-family: 'Space Grotesk', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  overflow: hidden;
  transition: background 0.5s ease;
}
body.persona-elia {
  background: #0d1e2e;
}
body.persona-sofia {
  background: #1e0d18;
}
.main {
  transition: background 0.5s ease;
}
body.persona-elia .main,
body.persona-elia .chat-area,
body.persona-elia .input-area {
  background: linear-gradient(160deg, #0a1929 0%, #0d2137 100%);
}
body.persona-sofia .main,
body.persona-sofia .chat-area,
body.persona-sofia .input-area {
  background: linear-gradient(160deg, #1a0a14 0%, #2a0d1e 100%);
}
body.persona-elia .input-area { border-top-color: rgba(0,180,255,0.15); }
body.persona-sofia .input-area { border-top-color: rgba(255,100,180,0.15); }

/* ── Persona backgrounds in LIGHT mode ── */
body.light.persona-elia {
  background: #dff0fb;
}
body.light.persona-sofia {
  background: #fce8f3;
}
body.light.persona-elia .main,
body.light.persona-elia .chat-area,
body.light.persona-elia .input-area {
  background: linear-gradient(160deg, #e8f5fd 0%, #d4edf9 100%);
}
body.light.persona-sofia .main,
body.light.persona-sofia .chat-area,
body.light.persona-sofia .input-area {
  background: linear-gradient(160deg, #fdeef7 0%, #fad9ee 100%);
}
body.light.persona-elia .input-area  { border-top-color: rgba(0,140,220,0.18); }
body.light.persona-sofia .input-area { border-top-color: rgba(220,80,160,0.18); }

/* ─── SIDEBAR ────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: rgba(18,18,24,0.97);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
  transition: width .25s cubic-bezier(.4,0,.2,1),
              box-shadow .25s ease;
  overflow: hidden;
}
/* Collapsed */
body.sidebar-collapsed .sidebar {
  width: var(--sidebar-collapsed-w);
  border-right-color: transparent;
}
body.sidebar-collapsed .main {
  margin-left: var(--sidebar-collapsed-w);
}
/* Hover-reveal quando collassata */
body.sidebar-collapsed .sidebar:hover {
  width: var(--sidebar-w);
  box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  border-right-color: var(--border);
}

/* Main transition */
.main {
  transition: margin-left .25s cubic-bezier(.4,0,.2,1);
}

/* Toggle button — galleggia sul bordo sinistro del main */
.sidebar-toggle {
  position: fixed;
  top: 14px;
  left: calc(var(--sidebar-w) - 1px);
  z-index: 200;
  width: 22px; height: 22px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 0 6px 6px 0;
  color: var(--muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
  transition: left .25s cubic-bezier(.4,0,.2,1),
              color .15s, background .15s;
}
.sidebar-toggle:hover {
  color: var(--text);
  background: var(--surface);
}
body.sidebar-collapsed .sidebar-toggle {
  left: var(--sidebar-collapsed-w);
}
body.sidebar-collapsed .sidebar:hover ~ .sidebar-toggle {
  left: var(--sidebar-w);
}
.sidebar-toggle svg {
  transition: transform .25s ease;
}
body.sidebar-collapsed .sidebar-toggle svg {
  transform: rotate(180deg);
}

.sidebar-logo {
  padding: 14px 14px 10px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid #252525;
  flex-shrink: 0;
}
.sidebar-logo img {
  width: 28px; height: 28px;
  border-radius: 7px; object-fit: cover;
  filter: drop-shadow(0 0 6px rgba(0,191,255,0.6));
  animation: logoGlow 3s ease-in-out infinite;
}
@keyframes logoGlow {
  0%,100% { filter: drop-shadow(0 0 6px rgba(0,191,255,0.5)); }
  50%      { filter: drop-shadow(0 0 14px rgba(0,220,255,.85)); }
}
.sidebar-logo span {
  font-size: 14px; font-weight: 700; color: #ececec; flex:1;
}

/* ── new-chat button in header ── */
.sidebar-new-btn {
  width: 26px; height: 26px;
  border-radius: 7px;
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: all .15s;
}
.sidebar-new-btn:hover { color: var(--text); border-color: var(--orange); }

/* ── Tab bar ── */
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid #252525;
  flex-shrink: 0;
}
.sidebar-tab {
  flex: 1;
  padding: 8px 4px;
  background: none; border: none;
  color: var(--muted);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 11px; font-weight: 600;
  cursor: pointer;
  text-transform: uppercase; letter-spacing: .4px;
  border-bottom: 2px solid transparent;
  transition: all .15s;
}
.sidebar-tab.active { color: var(--orange); border-bottom-color: var(--orange); }
.sidebar-tab:hover:not(.active) { color: var(--text); }

/* ── Scrollable body ── */
.sidebar-body {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 6px 6px 8px;
}
.sidebar-body::-webkit-scrollbar { width: 3px; }
.sidebar-body::-webkit-scrollbar-thumb { background: var(--faint); border-radius: 2px; }

/* ── Section label (date group / folder) ── */
.sb-section-label {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted);
  padding: 10px 8px 4px;
}

/* ── Chat item ── */
.sb-chat-item {
  display: flex; align-items: center; gap: 0;
  border-radius: 7px;
  cursor: pointer;
  transition: background .12s;
  position: relative;
  padding: 0;
  margin: 1px 0;
}
.sb-chat-item:hover { background: #1e1e22; }
.sb-chat-item.active { background: #252528; }

.sb-chat-title {
  flex: 1; padding: 7px 8px;
  font-size: 12px; color: #d0d0d8;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 1.35;
}
.sb-chat-item.active .sb-chat-title { color: var(--orange); font-weight: 500; }

.sb-chat-actions {
  display: none; gap: 2px; padding-right: 5px; flex-shrink: 0;
}
.sb-chat-item:hover .sb-chat-actions { display: flex; }
.sb-chat-action {
  width: 22px; height: 22px;
  border-radius: 5px; border: none;
  background: none; color: var(--muted);
  cursor: pointer; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  transition: all .12s;
}
.sb-chat-action:hover { background: rgba(255,255,255,.08); color: var(--text); }
.sb-chat-action.del:hover { color: #ff5555; }

/* ── Empty state ── */
.sb-empty {
  text-align: center; padding: 24px 12px;
  color: var(--muted); font-size: 12px; line-height: 1.6;
}
.sb-empty-icon { font-size: 28px; display: block; margin-bottom: 8px; opacity: .5; }

/* ── Projects ── */
.sb-project-item {
  border-radius: 8px;
  border: 1px solid transparent;
  margin: 3px 0;
  cursor: pointer;
  transition: all .15s;
  overflow: hidden;
}
.sb-project-item:hover { background: #1e1e22; border-color: var(--border); }
.sb-project-item.active { background: rgba(255,140,66,.07); border-color: rgba(255,140,66,.25); }

.sb-project-header {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 10px;
}
.sb-project-emoji { font-size: 15px; flex-shrink: 0; }
.sb-project-name {
  flex: 1; font-size: 12px; font-weight: 600;
  color: #d0d0d8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sb-project-item.active .sb-project-name { color: var(--orange); }
.sb-project-chevron {
  font-size: 10px; color: var(--muted);
  transition: transform .2s;
  flex-shrink: 0;
}
.sb-project-item.open .sb-project-chevron { transform: rotate(90deg); }

.sb-project-chats {
  display: none;
  padding: 0 6px 6px 26px;
  flex-direction: column; gap: 1px;
}
.sb-project-item.open .sb-project-chats { display: flex; }

.sb-project-chat {
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 11px; color: var(--muted);
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: all .12s;
}
.sb-project-chat:hover { background: #252528; color: var(--text); }
.sb-project-chat.active { color: var(--orange); font-weight: 500; }

.sb-add-project-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 10px;
  border-radius: 7px; border: 1px dashed var(--border);
  background: none; color: var(--muted);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 12px; cursor: pointer;
  width: 100%; margin-top: 6px;
  transition: all .15s;
}
.sb-add-project-btn:hover { border-color: var(--orange); color: var(--orange); }

/* ── Sidebar footer ── */
.sidebar-footer {
  flex-shrink: 0;
  padding: 8px 8px 10px;
  border-top: 1px solid #252525;
}
.sidebar-footer a {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 12px;
  background: linear-gradient(135deg,#4285f4,#7c3aed);
  color: #fff; text-decoration: none;
  border-radius: 9px; font-size: 13px; font-weight: 700;
  transition: opacity .15s;
}
.sidebar-footer a:hover { opacity: .85; }

.nav-sep { height: 1px; background: #252525; margin: 10px 6px 8px; }

/* ─── MAIN AREA ─────────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
  transition: margin-left .25s cubic-bezier(.4,0,.2,1);
}

/* ─── TOP BAR ───────────────────────────────────────────────────────── */
.topbar {
  height: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-left {
  display: flex; align-items: center; gap: 12px;
}

.topbar-back-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: rgba(255,140,66,0.08);
  border: 1px solid rgba(255,140,66,0.35);
  border-radius: 8px;
  color: var(--orange);
  font-size: 12px; font-weight: 600;
  text-decoration: none;
  transition: all .15s;
  white-space: nowrap;
}
.topbar-back-btn:hover {
  background: rgba(255,140,66,0.18);
  border-color: var(--orange);
  color: #fff;
}

.model-badge {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 20px;
  font-family: 'Space Mono', monospace;
  font-size: 11px; font-weight: 700;
  color: var(--green);
}
.model-badge::before {
  content: '';
  width: 6px; height: 6px;
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--green);
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

.topbar-title {
  font-size: 15px; font-weight: 600; color: var(--text);
}

/* Persona switcher */
.persona-switcher {
  display: flex; gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}
.persona-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 12px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 12px; font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.persona-btn:hover { color: var(--text); }
.persona-btn.active {
  background: var(--orange);
  color: #fff;
  font-weight: 700;
}

.persona-btn.placeholder-hint-neutro {
  box-shadow: 0 0 0 2px rgba(255,140,66,0.7), 0 0 10px rgba(255,140,66,0.4);
  border-color: rgba(255,140,66,0.8);
  transition: box-shadow .4s ease, border-color .4s ease;
}
/* ── Glow suggerimento placeholder ── */
.persona-btn.placeholder-hint-elia {
  box-shadow: 0 0 0 2px rgba(0,180,255,0.6), 0 0 10px rgba(0,180,255,0.35);
  border-color: rgba(0,180,255,0.7);
  transition: box-shadow .4s ease, border-color .4s ease;
}
.persona-btn.placeholder-hint-sofia {
  box-shadow: 0 0 0 2px rgba(255,100,180,0.6), 0 0 10px rgba(255,100,180,0.35);
  border-color: rgba(255,100,180,0.7);
  transition: box-shadow .4s ease, border-color .4s ease;
}

.topbar-right {
  display: flex; align-items: center; gap: 8px;
}

/* Lang picker */
.lang-select {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 7px;
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 12px; padding: 5px 8px;
  cursor: pointer; outline: none;
}

/* Mobile lang: bandiera cliccabile sopra un select invisibile */
.lang-mobile-wrap {
  display: none;
  position: relative;
  width: 36px; height: 36px;
  flex-shrink: 0;
}
.lang-flag {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  pointer-events: none;
  border-radius: 8px;
  border: 1px solid var(--border2);
  background: var(--surface2);
}
.lang-select-mobile {
  position: absolute; inset: 0;
  opacity: 0;
  width: 100%; height: 100%;
  cursor: pointer;
  font-size: 16px; /* prevent iOS zoom */
}

/* New chat btn */
.new-chat-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--muted);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 12px; font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.new-chat-btn:hover { color: var(--text); border-color: var(--orange); }

/* Plan badge */
.plan-badge {
  display: flex; align-items: center; gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px; font-weight: 700;
  font-family: 'Space Mono', monospace;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
  user-select: none;
}
.plan-badge.free {
  background: rgba(255,140,66,0.12);
  border: 1px solid rgba(255,140,66,0.3);
  color: var(--orange);
}
.plan-badge.free:hover {
  background: rgba(255,140,66,0.22);
  border-color: var(--orange);
}
.plan-badge.premium {
  background: linear-gradient(135deg, rgba(255,215,0,0.15), rgba(255,140,66,0.15));
  border: 1px solid rgba(255,215,0,0.45);
  color: #ffd700;
}
.plan-badge.premium:hover {
  background: linear-gradient(135deg, rgba(255,215,0,0.25), rgba(255,140,66,0.25));
}

/* Premium lock overlay on buttons */
.icon-btn.locked {
  opacity: 0.38;
  position: relative;
  cursor: not-allowed;
}
.icon-btn.locked::after {
  content: '🔒';
  position: absolute;
  font-size: 9px;
  bottom: -1px; right: -1px;
  line-height: 1;
}

/* ── PREMIUM MODAL ────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 9000;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 20px;
  padding: 32px 28px 26px;
  width: min(420px, 92vw);
  display: flex; flex-direction: column; gap: 20px;
  position: relative;
  animation: modalIn .25s ease;
}
@keyframes modalIn {
  from { opacity:0; transform: scale(.93) translateY(10px); }
  to   { opacity:1; transform: none; }
}
.modal-close {
  position: absolute; top: 14px; right: 16px;
  background: none; border: none;
  color: var(--muted); font-size: 20px; cursor: pointer;
  line-height: 1; padding: 4px;
  transition: color .15s;
}
.modal-close:hover { color: var(--text); }

/* ─── FOTOCAMERA IN-PAGE ─────────────────────────────────────────────── */
.camera-modal-box { width: min(480px, 94vw); padding-top: 44px; }
.camera-preview-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
}
.camera-preview-wrap video {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.camera-error {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; text-align: center;
  color: #fff; font-size: 13px; line-height: 1.5;
  background: rgba(0,0,0,.6);
}
.camera-modal-actions { display: flex; justify-content: center; }
.camera-shoot-btn {
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 12px 28px;
  font-size: 15px; font-weight: 600;
  font-family: 'Space Grotesk', sans-serif;
  cursor: pointer;
  transition: transform .12s, opacity .15s;
}
.camera-shoot-btn:hover { transform: scale(1.04); }
.camera-shoot-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }


.modal-header { text-align: center; }
.modal-header .modal-icon {
  font-size: 42px; display: block; margin-bottom: 10px;
}
.modal-header h3 {
  font-size: 20px; font-weight: 700; color: var(--text);
  margin-bottom: 6px;
}
.modal-header p {
  font-size: 13px; color: var(--muted); line-height: 1.5;
}

.plan-cards {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.plan-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.plan-card.current { border-color: var(--orange); background: rgba(255,140,66,0.05); }
.plan-card.highlight { border-color: #ffd700; background: rgba(255,215,0,0.05); }
.plan-card .plan-name {
  font-size: 13px; font-weight: 700; color: var(--text);
}
.plan-card .plan-price {
  font-size: 11px; color: var(--muted);
  font-family: 'Space Mono', monospace;
}
.plan-card ul {
  list-style: none; display: flex; flex-direction: column; gap: 5px;
}
.plan-card ul li {
  font-size: 11px; color: var(--muted); display: flex; gap: 6px;
}
.plan-card ul li.ok { color: var(--text); }
.plan-card ul li::before { content: '✓'; color: var(--green); flex-shrink:0; }
.plan-card ul li.no::before { content: '✗'; color: var(--faint); }
.plan-card ul li.no { color: var(--faint); }

.modal-unlock {
  display: flex; flex-direction: column; gap: 10px;
}
.modal-unlock label {
  font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px;
}
.modal-unlock-row {
  display: flex; gap: 8px;
}
.modal-unlock input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 10px;
  color: var(--text);
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  padding: 9px 14px;
  outline: none;
  transition: border-color .15s;
}
.modal-unlock input:focus { border-color: #ffd700; }
.modal-unlock input.shake {
  animation: shake .35s ease;
  border-color: #ff4444;
}
@keyframes shake {
  0%,100%{transform:translateX(0)}
  20%{transform:translateX(-6px)}
  40%{transform:translateX(6px)}
  60%{transform:translateX(-4px)}
  80%{transform:translateX(4px)}
}
.modal-unlock-btn {
  padding: 9px 16px;
  background: linear-gradient(135deg, #ffd700, #ff8c42);
  border: none; border-radius: 10px;
  color: #111; font-weight: 700; font-size: 13px;
  cursor: pointer; white-space: nowrap;
  transition: opacity .15s;
}
.modal-unlock-btn:hover { opacity: .85; }
.modal-downgrade-btn {
  background: none; border: none;
  color: var(--muted); font-size: 12px;
  cursor: pointer; text-align: center;
  text-decoration: underline;
  display: none;
}
.modal-downgrade-btn.visible { display: block; }

/* Web search badge */
.web-badge {
  display: none;
  align-items: center; gap: 5px;
  padding: 4px 10px;
  background: rgba(66,133,244,0.12);
  border: 1px solid rgba(66,133,244,0.35);
  border-radius: 20px;
  font-size: 11px; font-weight: 700;
  color: var(--blue);
  font-family: 'Space Mono', monospace;
  animation: fadeIn .4s ease;
}
.web-badge.visible { display: flex; }
@keyframes fadeIn { from{opacity:0;transform:translateY(-4px)} to{opacity:1;transform:none} }

/* Web search indicator on bubble */
.web-search-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; color: var(--blue);
  font-family: 'Space Mono', monospace;
  margin-bottom: 6px;
  opacity: .8;
}

.vision-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; color: #a855f7;
  font-family: 'Space Mono', monospace;
  margin-bottom: 6px;
  opacity: .85;
}

/* FIX 2026-09-19: indicatore discreto di quale modello/provider ha
   risposto — richiesto per monitorare al volo i vari LLM (fallback,
   auto-riparazione) senza aprire i log Vercel. Volutamente defilato:
   grigio neutro, sotto il testo (non sopra come i tag colorati "web"/
   "vision" che segnalano una FEATURE attiva), piccolo, sempre presente
   ma mai in competizione visiva con la risposta. */
.model-used-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 9px; color: var(--muted, #9a9a9a);
  font-family: 'Space Mono', monospace;
  margin-top: 8px;
  opacity: .45;
  transition: opacity .15s ease;
  user-select: none;
}
.model-used-tag:hover { opacity: .8; }

/* ─── CHAT AREA ─────────────────────────────────────────────────────── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  position: relative;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 0;
  scroll-behavior: smooth;
  min-height: 0;
}
.chat-area::-webkit-scrollbar { width: 4px; }
.chat-area::-webkit-scrollbar-thumb { background: var(--faint); border-radius: 2px; }

/* Welcome screen */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 32px 20px 20px;
  text-align: center;
  gap: 14px;
  animation: fadeUp .5s ease;
}
@keyframes fadeUp { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:none; } }

.welcome-logo-wrap {
  position: relative;
  width: 150px; height: 150px;
  display: flex; align-items: center; justify-content: center;
  animation: logoFloat 4s ease-in-out infinite;
}
@keyframes logoFloat {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}
.welcome-persona-img {
  width: 130px; height: 130px;
  object-fit: contain;
  position: relative; z-index: 2;
  transition: opacity .4s ease, transform .3s ease;
}
.welcome-persona-img:not([src=""]) {
  animation: logoSwapIn .35s ease;
}
@keyframes logoSwapIn {
  from { opacity: 0; transform: scale(0.88); }
  to   { opacity: 1; transform: scale(1); }
}
.logo-glow-ring {
  --glow-color: #a855f7;
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 1;
}
.logo-glow-ring::before {
  content: '';
  position: absolute;
  inset: 0; border-radius: 50%;
  box-shadow: 0 0 20px 6px var(--glow-color), inset 0 0 20px 2px var(--glow-color);
  opacity: 0.45;
  animation: glowPulse 2.5s ease-in-out infinite;
}
.logo-glow-ring::after {
  content: '';
  position: absolute;
  inset: -10px; border-radius: 50%;
  border: 1.5px solid var(--glow-color);
  opacity: 0;
  animation: ringExpand 2.5s ease-out infinite;
}
@keyframes glowPulse {
  0%,100% { opacity: 0.3; transform: scale(0.97); }
  50%     { opacity: 0.65; transform: scale(1.03); }
}
@keyframes ringExpand {
  0%   { transform: scale(0.95); opacity: 0.6; }
  100% { transform: scale(1.55); opacity: 0; }
}
.persona-btn-logo {
  width: 20px; height: 20px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 4px;
}

.welcome h2 {
  font-size: 28px; font-weight: 700; color: var(--text);
  line-height: 1.2;
}
.welcome h2 span { color: var(--orange); }
.welcome p {
  font-size: 14px; color: var(--muted); max-width: 360px; line-height: 1.6;
}
.app-footer {
  flex-shrink: 0;
  text-align: center;
  font-size: 10.5px;
  color: var(--muted);
  opacity: .55;
  padding: 4px 12px 6px;
  line-height: 1.4;
}

/* Back to orchestrator button */
.back-to-orch-btn {
  display: inline-flex; align-items: center; gap: 7px;
  margin-top: 8px;
  padding: 9px 20px;
  background: rgba(255,140,66,0.08);
  border: 1px solid rgba(255,140,66,0.25);
  border-radius: 24px;
  color: var(--orange);
  font-size: 13px; font-weight: 600;
  text-decoration: none;
  transition: all .2s;
  letter-spacing: .2px;
}
.back-to-orch-btn:hover {
  background: rgba(255,140,66,0.16);
  border-color: rgba(255,140,66,0.5);
  transform: translateX(-3px);
}

/* Messages */
.message-group {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: var(--chat-max);
  width: 100%;
  margin: 0 auto;
  padding: 4px 0;
}

.message {
  display: flex;
  gap: 12px;
  animation: msgIn .2s ease;
}
@keyframes msgIn { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:none; } }

.message.user { flex-direction: row-reverse; }

.avatar {
  width: 32px; height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  font-weight: 700;
}
.avatar.ai-avatar {
  background: linear-gradient(135deg, #f4f4f8, #e4e4ee);
  border: 1px solid var(--border2);
  font-size: 16px;
  overflow: hidden;
  padding: 0;
  position: relative; /* serve da ancora per l'overlay .matrix-rain-canvas */
}
.avatar.ai-avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

/* ── Effetto "digital rain" sulla goccia durante la generazione di codice
   (richiesto da VinDimax 2026-09-28, ispirato all'effetto Matrix) ─────────
   Attivo SOLO in modalità Coding, mentre la goccia genera la risposta —
   puramente estetico, non tocca la velocità reale dello streaming. */
.matrix-rain-canvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  border-radius: 8px;
  pointer-events: none;
  opacity: 0.92;
  transition: opacity 0.35s ease;
}
.matrix-rain-canvas.matrix-rain-fadeout {
  opacity: 0;
}

/* ── Goccia animata (idea di VinDimax, adattata per PNG) ────────────────
   Il codice originale presumeva una goccia SVG con parti separate
   (.node/.path/#drop) animabili singolarmente. I loghi AInstAIn sono PNG
   (immagini piatte) — qui adattiamo lo stesso spirito (bagliore pulsante
   che cambia colore) usando drop-shadow + hue-rotate, che funzionano su
   qualunque immagine, PNG o SVG. */
.avatar.ai-avatar img.goccia-idle,
.welcome-persona-img.goccia-idle {
  animation: goccia-breathe 3s ease-in-out infinite;
}
@keyframes goccia-breathe {
  0%, 100% { filter: drop-shadow(0 0 2px #6cf); }
  50%      { filter: drop-shadow(0 0 6px #9af); }
}

.avatar.ai-avatar img.goccia-thinking,
.welcome-persona-img.goccia-thinking {
  animation: goccia-thinking 1.8s ease-in-out infinite;
}
@keyframes goccia-thinking {
  0%   { filter: drop-shadow(0 0 3px #0ff) hue-rotate(0deg)   brightness(1); }
  50%  { filter: drop-shadow(0 0 10px #a0f) hue-rotate(140deg) brightness(1.15); }
  100% { filter: drop-shadow(0 0 3px #0ff) hue-rotate(360deg) brightness(1); }
}

.avatar.ai-avatar img.goccia-answer,
.welcome-persona-img.goccia-answer {
  animation: goccia-flash 0.6s ease;
}
@keyframes goccia-flash {
  0%   { filter: drop-shadow(0 0 3px #fff); }
  50%  { filter: drop-shadow(0 0 16px #fff); }
  100% { filter: drop-shadow(0 0 2px #6cf); }
}
.avatar.user-avatar {
  background: var(--orange);
  color: #fff;
  font-size: 12px;
}

.bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.65;
}
.message.ai .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
  color: var(--text);
}
.message.user .bubble {
  background: var(--orange);
  color: #fff;
  border-top-right-radius: 4px;
}
.bubble p { margin-bottom: 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble code {
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  background: rgba(255,255,255,0.08);
  padding: 2px 5px;
  border-radius: 4px;
}
.bubble pre {
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.bubble pre code { background: none; padding: 0; }

.msg-time {
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
  font-family: 'Space Mono', monospace;
  align-self: flex-end;
}

/* Typing indicator */
.typing-indicator {
  display: none;
  align-items: center;
  gap: 12px;
  max-width: var(--chat-max);
  width: 100%;
  margin: 0 auto;
  padding: 4px 0;
}
.typing-indicator.visible { display: flex; }
.typing-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  border-top-left-radius: 4px;
  padding: 12px 16px;
  display: flex; gap: 5px; align-items: center;
}
.typing-dot {
  width: 6px; height: 6px;
  background: var(--muted);
  border-radius: 50%;
  animation: typingDot 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes typingDot {
  0%,100% { transform: translateY(0); opacity: .4; }
  50%      { transform: translateY(-4px); opacity: 1; }
}

/* ─── INPUT BAR ─────────────────────────────────────────────────────── */
.input-area {
  flex-shrink: 0;
  padding: 16px 20px 20px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.input-wrapper {
  max-width: var(--chat-max);
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 16px;
  padding: 8px 8px 8px 14px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  transition: border-color .15s;
}
.input-wrapper:focus-within {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(255,140,66,0.1);
}

/* Image preview (multi-attachment chips) */
#image-preview-container {
  display: none;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0 8px;
  max-width: var(--chat-max);
  margin: 0 auto 4px;
}
#image-preview-container.visible { display: flex; }
.img-chip {
  position: relative;
  display: inline-block;
}
.img-chip img {
  height: 60px;
  border-radius: 8px;
  border: 1px solid var(--border2);
  object-fit: cover;
  display: block;
}
.remove-img {
  position: absolute;
  top: -7px; right: -7px;
  width: 20px; height: 20px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 50%;
  color: var(--muted); cursor: pointer;
  font-size: 11px; display: flex; align-items: center; justify-content: center;
}
.remove-img:hover { background: rgba(220,50,50,0.3); color: #fff; }

/* Doc preview chip (multi-attachment) */
.doc-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: rgba(66,133,244,0.1);
  border: 1px solid rgba(66,133,244,0.3);
  border-radius: 8px;
}
.doc-chip .doc-chip-name {
  font-size: 12px; color: #4285f4; font-weight: 600;
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.doc-chip .doc-chip-meta { font-size: 11px; color: var(--muted); }
.doc-chip button {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 13px; line-height: 1; padding: 0 2px;
}
.doc-chip button:hover { color: #ff5555; }

#chat-input {
  flex: 1;
  background: none; border: none; outline: none;
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  min-height: 24px;
  max-height: 120px;
  overflow-y: auto;
}
#chat-input::placeholder { color: var(--muted); }

.input-actions {
  display: flex; gap: 4px; align-items: flex-end;
}

.icon-btn {
  width: 36px; height: 36px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  transition: all .15s;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}
.icon-btn:hover { color: var(--text); border-color: var(--border2); }
.icon-btn.active { color: var(--orange); border-color: var(--orange); background: rgba(255,140,66,0.1); }
.icon-btn.camera-only-mobile { display: none; } /* visibile solo su mobile, vedi media query */
/* FIX v2: la tecnica "clip a 1px" nascondeva bene l'input su desktop, ma
   su alcuni Android/Chrome causava un problema diverso: tornando dalla
   fotocamera nativa, l'evento "change" non veniva più collegato a un
   input così minuscolo, e la foto scattata si perdeva silenziosamente.
   Overlay a piena dimensione con opacity:0 è la tecnica più compatibile
   per input file su mobile (usata comunemente per pulsanti upload/camera):
   stessa area cliccabile del pulsante, invisibile, ma "vero" agli occhi
   del sistema operativo quando restituisce il file. */
.icon-btn input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  margin: 0;
  padding: 0;
  border: 0;
}
.icon-btn.recording { color: #ff4444; border-color: #ff4444; animation: recPulse 1s infinite; }
@keyframes recPulse { 0%,100%{box-shadow:none} 50%{box-shadow:0 0 8px rgba(255,68,68,0.5)} }

.send-btn {
  width: 36px; height: 36px;
  border-radius: 9px;
  border: none;
  background: var(--orange);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  transition: all .15s;
  flex-shrink: 0;
}
.send-btn:hover { background: var(--orange2); transform: scale(1.05); }
.send-btn:disabled { background: var(--faint); cursor: not-allowed; transform: none; }

/* ── STOP GENERATION BUTTON ── */
.stop-btn {
  display: none;
  width: 36px; height: 36px;
  border-radius: 9px;
  border: 1px solid rgba(255,80,80,0.4);
  background: rgba(255,80,80,0.12);
  color: #ff5555;
  cursor: pointer;
  align-items: center; justify-content: center;
  font-size: 13px;
  transition: all .15s;
  flex-shrink: 0;
}
.stop-btn:hover { background: rgba(255,80,80,0.25); border-color: #ff5555; }
body.streaming .stop-btn  { display: flex; }
body.streaming .send-btn  { display: none; }

.input-hint {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px;
  font-family: 'Space Mono', monospace;
}

/* ── WELCOME INFO BUTTON ── */
.welcome-info-btn {
  display: flex; align-items: center; gap: 6px;
  background: none; border: 1px solid var(--border2);
  border-radius: 20px; color: var(--muted);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 12px; padding: 5px 12px;
  cursor: pointer; transition: all .15s;
}
.welcome-info-btn:hover { color: var(--text); border-color: var(--orange); }

.welcome-info-tooltip {
  display: none;
  flex-direction: column; gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 12px; color: var(--muted);
  font-family: 'Space Mono', monospace;
  text-align: left;
  animation: fadeUp .2s ease;
  width: 100%; max-width: 320px;
}
.welcome-info-tooltip.visible { display: flex; }
.welcome-info-tooltip span { display: flex; align-items: center; gap: 8px; }

/* Hidden file inputs */
#file-input, #doc-input { display: none; }

/* Doc preview */
#doc-preview-container {
  max-width: var(--chat-max);
  margin: 0 auto 6px;
  box-sizing: border-box;
}

/* ─── ERROR / STATUS TOAST ──────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 100px; left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #ff4444;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px; font-weight: 600;
  opacity: 0;
  transition: all .3s;
  z-index: 999;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ─── MOBILE ────────────────────────────────────────────────────────── */
/* ── DESKTOP WELCOME BOX ────────────────────────────────────────────── */
@media (min-width: 769px) {
  /* Box inserito nel welcome via JS: reset bordo e sfondo */
  .input-area.inside-welcome-desktop {
    border-top: none;
    background: transparent;
    padding: 0;
    width: 100%;
    max-width: var(--chat-max);
    margin: 0 auto;
  }
  .input-area.inside-welcome-desktop .input-wrapper {
    border-radius: 20px;
    box-shadow: 0 4px 28px rgba(0,0,0,0.25);
    max-width: 100%;
    padding: 14px 12px 14px 18px;
  }
  .input-area.inside-welcome-desktop #chat-input {
    min-height: 56px;
    font-size: 15px;
  }
}

@media (max-width: 768px) {
  /* Sidebar diventa drawer overlay */
  .sidebar {
    width: var(--sidebar-w) !important;
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    z-index: 95;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-toggle { display: none; }
  .mobile-menu-btn { display: flex; }

  /* Pulsante scatta foto: visibile solo su mobile, dove ha senso */
  .icon-btn.camera-only-mobile { display: flex; }

  html, body { height: 100%; overflow: hidden; }

  .main {
    margin-left: 0 !important;
    height: 100vh; height: 100dvh;
    display: flex; flex-direction: column;
    overflow: hidden; position: relative;
  }

  /* Topbar compatta */
  .topbar {
    padding: 0 10px; height: 52px;
    flex-wrap: nowrap; gap: 6px; flex-shrink: 0;
    position: relative; z-index: 10;
    /* FIX: prima gli elementi in eccesso (piano FREE/Premium, contatore
       messaggi) finivano fuori dallo schermo senza modo di raggiungerli.
       Ora la barra scorre orizzontalmente (swipe) invece di tagliare via i
       controlli — scrollbar nascosta per restare pulita visivamente. */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .topbar::-webkit-scrollbar { display: none; }
  .topbar-left, .topbar-right { flex-shrink: 0; }
  .topbar-left { gap: 6px; }
  .topbar-right { gap: 4px; }
  .topbar-title { display: none; }
  .topbar-back-btn span { display: none; }
  .topbar-back-btn { padding: 6px 8px; }
  .model-badge { display: none; }
  .web-badge { display: none; }
  .lang-select { display: none; }
  .lang-mobile-wrap { display: flex; }
  .export-btn { display: none; }

  /* Persona switcher compatto */
  .persona-switcher { gap: 2px; padding: 2px; }
  .persona-btn { padding: 5px 8px; font-size: 11px; }
  .persona-btn span { display: none; }
  .persona-btn img { width: 16px; height: 16px; }

  /* Input area */
  .input-area {
    position: static;
    padding: 8px 10px max(12px, env(safe-area-inset-bottom));
    background: var(--bg);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
  }
  .input-wrapper { border-radius: 14px; padding: 7px 7px 7px 12px; gap: 5px; }
  #chat-input { font-size: 16px; min-height: 24px; }
  .icon-btn, .send-btn { width: 38px; height: 38px; border-radius: 8px; }
  .input-hint { display: none; }

  /* Chat area */
  .chat-area {
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding: 8px 10px 12px; display: flex; flex-direction: column;
    flex: 1; min-height: 0;
  }

  /* ── STATO WELCOME (nessun messaggio) ───────────────────────
     Il .main diventa uno stacking context.
     Welcome occupa tutta la chat-area e centra verticalmente.
     Input-area viene sollevata al centro con translate.
  ─────────────────────────────────────────────────────────── */
  body:not(.has-messages) .chat-area {
    justify-content: center;
    padding-bottom: 130px; /* spazio per il box input galleggiante */
  }
  body:not(.has-messages) .welcome {
    flex: 0 0 auto;
    justify-content: center;
    padding: 20px 16px 16px;
    gap: 12px;
  }
  /* Quando il box è dentro il welcome su mobile */
  .input-area.inside-welcome {
    border-top: none;
    background: transparent;
    padding: 0;
    width: 100%;
  }
  .input-area.inside-welcome .input-wrapper {
    border-radius: 18px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    max-width: 100%;
  }

  /* ── STATO CHAT (messaggi presenti) ── */
  body.has-messages .input-area {
    position: static;
    border-top: 1px solid var(--border);
    background: var(--bg);
    padding: 8px 10px max(12px, env(safe-area-inset-bottom));
  }

  /* Welcome dimensioni */
  .welcome-logo-wrap { width: 100px; height: 100px; }
  .welcome-persona-img { width: 84px; height: 84px; }
  .welcome h2 { font-size: 20px; }
  .welcome p  { font-size: 13px; }
  .back-to-orch-btn { font-size: 12px; padding: 7px 16px; margin-top: 4px; }

  /* Bubble */
  .bubble { max-width: 88%; font-size: 13px; }

  /* Bottoni azione messaggio sempre visibili su touch */
  .msg-actions { display: flex; }

  /* New chat btn */
  .new-chat-btn span { display: none; }
  .new-chat-btn { padding: 6px 8px; }

  /* Plan badge */
  .plan-badge { font-size: 10px; padding: 3px 8px; }

  /* Previews */
  #image-preview-container { padding: 3px 0 6px; }
  #doc-preview-container { margin-bottom: 4px; }

  .toast { bottom: 80px; }

  /* Shortcuts panel full screen on mobile */
  .shortcuts-box { width: 94vw; padding: 20px 18px; }

  /* Memory modal */
  .memory-modal { padding: 20px 18px; }
}

@media (max-width: 400px) {
  .persona-btn { padding: 4px 6px; }
  .topbar { gap: 3px; }
  .icon-btn, .send-btn { width: 34px; height: 34px; }
}
/* ─── MARKDOWN FULL RENDERER ─────────────────────────────────────────── */
.md-h1 { font-size: 1.4em; font-weight: 700; margin: 10px 0 6px; color: var(--text); border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.md-h2 { font-size: 1.2em; font-weight: 700; margin: 10px 0 5px; color: var(--text); }
.md-h3 { font-size: 1.05em; font-weight: 700; margin: 8px 0 4px; color: var(--text); }

.md-blockquote {
  border-left: 3px solid var(--orange);
  margin: 6px 0; padding: 4px 12px;
  color: var(--muted); font-style: italic;
  background: rgba(255,140,66,0.05);
  border-radius: 0 6px 6px 0;
}

.md-hr { border: none; border-top: 1px solid var(--border2); margin: 10px 0; }

.md-link { color: var(--orange); text-decoration: underline; text-underline-offset: 2px; word-break: break-all; }
.md-link:hover { color: var(--orange2); }

.md-ul, .md-ol { margin: 6px 0 6px 18px; padding: 0; }
.md-ul { list-style-type: disc; }
.md-ol { list-style-type: decimal; }
.md-ul li, .md-ol li { margin: 2px 0; line-height: 1.55; }

.md-table-wrap { overflow-x: auto; margin: 8px 0; border-radius: 8px; border: 1px solid var(--border2); }
.md-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.md-table th { background: var(--surface2); color: var(--text); font-weight: 700; padding: 7px 12px; text-align: left; border-bottom: 1px solid var(--border2); }
.md-table td { padding: 6px 12px; border-bottom: 1px solid var(--border); color: var(--text); }
.md-table tr:last-child td { border-bottom: none; }
.md-table tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

/* Code block */
.code-block {
  position: relative;
  margin: 8px 0;
  background: #0a0a0c;
  border: 1px solid var(--border2);
  border-radius: 10px;
  overflow: hidden;
}
.code-lang {
  display: block;
  padding: 4px 12px;
  font-size: 10px; font-family: 'Space Mono', monospace;
  color: var(--muted);
  background: rgba(255,255,255,0.04);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: .5px;
}
.code-block pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.code-block code { font-family: 'Space Mono', monospace; font-size: 12px; line-height: 1.65; color: #e0e0e8; background: none; padding: 0; white-space: pre; }
.copy-code-btn {
  position: absolute; top: 4px; right: 6px;
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 5px; color: var(--muted);
  font-size: 11px; padding: 2px 6px;
  cursor: pointer; transition: all .12s;
}
.copy-code-btn:hover { color: var(--text); border-color: var(--orange); }

/* Inline code */
.inline-code {
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--orange);
}

/* Syntax highlight tokens — dark mode (default) */
.hl-kw   { color: #c792ea; font-weight: 600; }
.hl-str  { color: #c3e88d; }
.hl-cmt  { color: #637777; font-style: italic; }
.hl-num  { color: #f78c6c; }
.hl-tag  { color: #89ddff; font-weight: 600; }
.hl-attr { color: #ffcb6b; }
.hl-key  { color: #c792ea; }

/* Syntax highlight tokens — light mode */
body.light .hl-kw   { color: #7c3aed; }
body.light .hl-str  { color: #16a34a; }
body.light .hl-cmt  { color: #6b7280; }
body.light .hl-num  { color: #ea580c; }
body.light .hl-tag  { color: #0891b2; }
body.light .hl-attr { color: #b45309; }
body.light .hl-key  { color: #7c3aed; }

/* code-block: scuro in dark, grigio chiarissimo in light */
body.light .code-block { background: #f6f8fa; }
body.light .code-block code { color: #24292f; }
body.light .code-lang { background: rgba(0,0,0,.04); }
body.light .inline-code { background: rgba(0,0,0,.06); color: #c7254e; }

/* ─── STREAMING CURSOR ───────────────────────────────────────────────── */
.stream-cursor {
  display: inline-block;
  width: 2px; height: 1em;
  background: var(--orange);
  margin-left: 2px;
  vertical-align: text-bottom;
  border-radius: 1px;
  animation: cursorBlink .6s steps(1) infinite;
}
@keyframes cursorBlink { 0%,100%{opacity:1} 50%{opacity:0} }

/* ── Bolla collassata durante lo streaming ── */
.stream-bubble.collapsed {
  max-height: 96px;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, black 50%, transparent 100%);
  mask-image: linear-gradient(to bottom, black 50%, transparent 100%);
}
.stream-expand-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  margin-top: 4px;
  transition: all .15s;
  flex-shrink: 0;
}
.stream-expand-btn:hover { color: var(--text); border-color: var(--orange); }
.stream-expand-btn.hidden { display: none; }

/* ─── PROJECT / RENAME MODALS ────────────────────────────────────────── */
.mini-modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 9100;
  background: rgba(0,0,0,.65); backdrop-filter: blur(4px);
  align-items: center; justify-content: center;
}
.mini-modal-overlay.open { display: flex; }
.mini-modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 16px;
  padding: 24px 22px 20px;
  width: min(360px, 92vw);
  display: flex; flex-direction: column; gap: 14px;
  animation: modalIn .22s ease;
  position: relative;
}
.mini-modal h4 {
  font-size: 15px; font-weight: 700; color: var(--text); margin: 0;
}
.mini-modal label {
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px;
}
.mini-modal input, .mini-modal textarea {
  width: 100%;
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 9px; color: var(--text);
  font-family: 'Space Grotesk', sans-serif; font-size: 13px;
  padding: 9px 12px; outline: none;
  transition: border-color .15s;
  resize: none;
}
.mini-modal input:focus, .mini-modal textarea:focus { border-color: var(--orange); }
.mini-modal-row { display: flex; gap: 8px; align-items: center; }
.mini-modal-emoji {
  font-size: 22px; padding: 6px 10px;
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 9px; cursor: pointer;
  transition: border-color .15s; flex-shrink: 0;
}
.mini-modal-emoji:hover { border-color: var(--orange); }
.mini-modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.mini-btn {
  padding: 8px 16px; border-radius: 9px; border: none;
  font-family: 'Space Grotesk', sans-serif; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: opacity .15s;
}
.mini-btn.cancel { background: var(--surface2); color: var(--muted); }
.mini-btn.cancel:hover { color: var(--text); }
.mini-btn.confirm { background: var(--orange); color: #fff; }
.mini-btn.confirm:hover { opacity: .85; }
.mini-btn.danger { background: rgba(255,80,80,.15); color: #ff5555; border: 1px solid rgba(255,80,80,.3); }
.mini-btn.danger:hover { background: rgba(255,80,80,.25); }
.emoji-picker {
  display: none; flex-wrap: wrap; gap: 4px;
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 10px; padding: 8px;
  max-height: 100px; overflow-y: auto;
}
.emoji-picker.open { display: flex; }
.emoji-opt {
  font-size: 18px; cursor: pointer; padding: 3px 5px;
  border-radius: 6px; transition: background .1s;
}
.emoji-opt:hover { background: rgba(255,255,255,.1); }

/* ─── MENU OPZIONI ───────────────────────────────────────────────────── */
.options-wrap { position: relative; }
.options-btn {
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  padding: 5px 10px;
  display: flex; align-items: center; gap: 5px;
  transition: background .15s;
  white-space: nowrap;
}
.options-btn:hover { background: var(--surface2); }
.options-dropdown {
  /* FIX: prima era position:absolute rispetto al pulsante, dentro la
     topbar — da quando la topbar scorre orizzontalmente su mobile
     (overflow-x:auto), questo tagliava via il menu invece di mostrarlo.
     position:fixed + coordinate calcolate in JS (toggleOptionsMenu)
     lo svincola completamente da qualunque contenitore con overflow. */
  position: fixed;
  top: 60px;
  right: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  min-width: 210px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  z-index: 2000;
  display: none;
  flex-direction: column;
  gap: 1px;
}
.options-dropdown.open { display: flex; }
.opt-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  background: none; border: none; width: 100%;
  text-align: left;
  transition: background .12s;
}
.opt-item:hover { background: var(--surface2); }
.opt-left { display: flex; align-items: center; gap: 8px; }
.opt-badge {
  font-size: 11px; padding: 2px 7px;
  border-radius: 20px; border: 1px solid var(--border2);
  color: var(--muted);
}
.opt-badge.on   { border-color: var(--orange); color: var(--orange); background: rgba(232,101,10,.1); }
.opt-badge.gold { border-color: #ffd700; color: #ffd700; background: rgba(255,215,0,.1); }
.opt-divider { border: none; border-top: 1px solid var(--border); margin: 3px 6px; }

/* ─── INDICATORE MODELLI MULTI-LLM ──────────────────────────────────── */
#multi-model-indicator {
  font-size: 10px; color: #ffd700;
  margin-top: 1px; display: none;
  letter-spacing: .3px;
}
body.multi-active #multi-model-indicator { display: block; }


/* ─── MENU OPZIONI ───────────────────────────────────────────────────── */
.options-btn {
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  padding: 5px 10px;
  display: flex; align-items: center; gap: 5px;
  transition: background .15s;
  white-space: nowrap;
  position: relative;
}
.options-btn:hover { background: var(--surface2); }
.options-dropdown {
  position: fixed;
  top: 60px;
  right: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  min-width: 200px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
  z-index: 2000;
  display: none;
  flex-direction: column;
  gap: 2px;
}
.options-dropdown.open { display: flex; }
.opt-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  background: none; border: none; width: 100%;
  text-align: left;
  transition: background .12s;
}
.opt-item:hover { background: var(--surface2); }
.opt-item .opt-label { display: flex; align-items: center; gap: 8px; }
.opt-item .opt-badge {
  font-size: 11px; padding: 2px 7px;
  border-radius: 20px; border: 1px solid var(--border2);
  color: var(--muted);
}
.opt-item .opt-badge.active { border-color: var(--orange); color: var(--orange); background: rgba(232,101,10,.1); }
.opt-item .opt-badge.gold   { border-color: #ffd700; color: #ffd700; background: rgba(255,215,0,.1); }
.opt-divider { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ─── INDICATORE MODELLI MULTI-LLM ──────────────────────────────────── */
#model-indicator {
  font-size: 10px;
  color: var(--muted);
  display: none;
}
body.multi-active #model-indicator { display: block; }


/* ─── TOGGLE MULTI-LLM ──────────────────────────────────────────────── */
#multi-mode-btn { background:transparent;border:1px solid var(--border2);border-radius:8px;color:var(--text);cursor:pointer;font-size:12px;padding:4px 8px;transition:background .15s,border-color .15s;white-space:nowrap; }
#multi-mode-btn:hover { background:var(--surface2); }
#multi-mode-btn.fast { background:rgba(232,101,10,.12);border-color:var(--orange);color:var(--orange); }
#multi-mode-btn.best { background:rgba(255,215,0,.12);border-color:#ffd700;color:#ffd700; }
.multi-badge { display:inline-flex;align-items:center;gap:4px;font-size:11px;color:#ffd700;border:1px solid rgba(255,215,0,.3);border-radius:20px;padding:2px 8px;margin-bottom:6px;background:rgba(255,215,0,.06); }
.multi-responses-panel { background:var(--surface2);border:1px solid var(--border);border-radius:10px;padding:10px 14px;margin-bottom:10px;font-size:12px;color:var(--muted); }
.multi-responses-panel summary { cursor:pointer;color:var(--orange); }


/* ─── PULSANTE AGENTE AI ────────────────────────────────────────────── */
#agent-mode-btn.active {
  background: var(--orange);
  color: #fff;
  border-color: var(--orange);
}
#agent-mode-btn.active:hover { opacity: .85; }
.icon-btn-sm {
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  transition: background .15s, border-color .15s;
}
.icon-btn-sm:hover { background: var(--surface2); }

/* ─── TOOL TAG nelle bubble agente ──────────────────────────────────── */
.agent-tool-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--orange);
  border: 1px solid rgba(232,101,10,.3);
  border-radius: 20px;
  padding: 2px 8px;
  margin-bottom: 8px;
  background: rgba(232,101,10,.06);
}
.agent-tag-expand { font-size: 9px; opacity: .7; }
.agent-steps-panel {
  font-size: 11.5px;
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  margin: -2px 0 8px;
  line-height: 1.5;
}
.agent-step-item { padding: 3px 0; }
.agent-step-item + .agent-step-item { border-top: 1px solid var(--border); margin-top: 3px; padding-top: 6px; }


/* ─── RICERCA CHAT IN SIDEBAR ───────────────────────────────────────── */
.sb-search-wrap {
  padding: 8px 10px 4px;
  position: relative;
}
.sb-search-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 6px 28px 6px 10px;
  font-size: 12px;
  color: var(--text);
  outline: none;
  box-sizing: border-box;
  transition: border-color .15s;
}
.sb-search-input:focus { border-color: var(--orange); }
.sb-search-input::placeholder { color: var(--muted); }
.sb-search-clear {
  position: absolute;
  right: 16px; top: 50%;
  transform: translateY(-50%);
  background: none; border: none;
  color: var(--muted); cursor: pointer;
  font-size: 13px; padding: 2px;
  display: none;
}
.sb-search-wrap:has(.sb-search-input:not(:placeholder-shown)) .sb-search-clear { display: block; }
.sb-chat-item.search-hidden { display: none; }
.sb-section-label.search-hidden { display: none; }

/* ─── MODALITÀ FOCUS ────────────────────────────────────────────────── */
body.focus-mode .topbar,
body.focus-mode .sidebar,
body.focus-mode .sidebar-toggle { display: none !important; }
body.focus-mode .main { margin-left: 0 !important; }
body.focus-mode .focus-exit-btn { display: flex !important; }
.focus-exit-btn {
  display: none;
  position: fixed;
  top: 12px; right: 12px;
  z-index: 1000;
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 12px;
  cursor: pointer;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 10px rgba(0,0,0,.3);
  transition: opacity .2s;
}
.focus-exit-btn:hover { opacity: .85; }

/* ─── PANNELLO IMPOSTAZIONI ─────────────────────────────────────────── */
.settings-panel {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 900;
}
.settings-panel.open { display: flex; }
.settings-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: min(420px, 92vw);
  max-height: 80vh;
  overflow-y: auto;
}
.settings-box h3 {
  font-size: 16px; font-weight: 700;
  color: var(--text); margin: 0 0 18px;
  display: flex; align-items: center; gap: 8px;
}
.settings-row {
  margin-bottom: 16px;
}
.settings-label {
  font-size: 12px; color: var(--muted);
  margin-bottom: 6px; display: flex;
  justify-content: space-between; align-items: center;
}
.settings-label span { color: var(--orange); font-weight: 600; }
.settings-slider {
  width: 100%;
  accent-color: var(--orange);
}
.settings-divider {
  border: none; border-top: 1px solid var(--border);
  margin: 18px 0;
}
.settings-reset-btn {
  width: 100%;
  background: rgba(255,85,85,.12);
  border: 1px solid rgba(255,85,85,.3);
  color: #ff5555;
  border-radius: 8px;
  padding: 9px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}
.settings-reset-btn:hover { background: rgba(255,85,85,.22); }


/* ─── CONTATORE MESSAGGI FREE ───────────────────────────────────────── */
#msg-counter {
  font-size: 11px;
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid var(--border2);
  background: transparent;
  white-space: nowrap;
  transition: color .2s, border-color .2s, background .2s;
  display: none; /* visibile solo per utenti Free */
}
#msg-counter.warn {
  color: #f0a500;
  border-color: #f0a500;
}
#msg-counter.danger {
  color: #ff5555;
  border-color: #ff5555;
  background: rgba(255,85,85,.08);
  font-weight: 700;
}
body.is-premium #msg-counter { display: none !important; }
body:not(.is-premium) #msg-counter { display: inline-flex; align-items: center; }


/* ─── SCROLL-TO-BOTTOM BUTTON ───────────────────────────────────────── */
#scroll-to-bottom {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--orange);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 50;
}
#scroll-to-bottom.visible {
  opacity: 1;
  pointer-events: auto;
}
#scroll-to-bottom:hover { transform: scale(1.1); }


/* ─── MARKDOWN EXTRA (h4, del, nested lists, new hl tokens) ─────────── */
.md-h4 { font-size: .95em; font-weight: 700; margin: 6px 0 3px; color: var(--text); }
del { text-decoration: line-through; opacity: .65; }
.md-ul-nested { margin: 2px 0 2px 16px; }

/* ─── PREFLIGHT NOTE (nota pre-risposta) ──────────────────────────── */
.preflight-note {
  display: flex; align-items: center; gap: 10px;
  max-width: var(--chat-max); width: 100%;
  margin: 0 auto; padding: 4px 0;
  animation: preflightIn .25s ease;
}
@keyframes preflightIn { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:none} }
.preflight-note.fade-out { animation: preflightOut .35s ease forwards; }
@keyframes preflightOut {
  from{opacity:1;transform:translateY(0);max-height:60px}
  to{opacity:0;transform:translateY(-4px);max-height:0;margin:0;padding:0}
}
.preflight-bubble {
  background: transparent;
  border: 1px dashed var(--border2);
  border-radius: 12px; border-top-left-radius: 3px;
  padding: 7px 14px; font-size: 12px; color: var(--muted);
  font-family: 'Space Mono', monospace; letter-spacing: .2px;
  display: flex; align-items: center; gap: 8px;
}
.preflight-dot {
  width: 5px; height: 5px; background: var(--orange);
  border-radius: 50%; flex-shrink: 0;
  animation: preflightPulse 1.2s ease-in-out infinite;
}
@keyframes preflightPulse {
  0%,100%{opacity:.3;transform:scale(.8)}
  50%{opacity:1;transform:scale(1.2)}
}
