/* =============================================
   TIPOGRAFIA UNIFICATA
   ============================================= */
body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 16px; /* Dimensione base consistente */
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Scala tipografica coerente */
h1, h2, h3, h4, h5, h6 {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 0.5em;
}

h1 { font-size: 1.75em; }
h2 { font-size: 1.5em; }
h3 { font-size: 1.25em; }
h4 { font-size: 1.1em; }

.brand strong {
  font-size: 1.3em;
  font-weight: 800;
}

.side-title {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-weight: 700;
  font-size: 0.95em;
}
/* =============================================
   ANTI-FLASH OF UNSTYLED CONTENT (FOUC) - CORRETTO
   ============================================= */
/* Mostra solo il preloader, nascondi il resto finché non è caricato */
body.loading .sidebar,
body.loading .main,
body.loading .mbar,
body.loading .composer,
body.loading .foot {
  visibility: hidden !important;
}

/* Assicura che il preloader sia visibile durante il 'loading' */
body.loading #preloader,
body.loading #preloader * {
  visibility: visible !important;
}

body.loaded * {
  visibility: visible !important;
}
/* =============================================
   1. VARIABILI GLOBALI E TEMI
   ============================================= */
:root {
  /* Palette Base (Tech 2.0) - RIVISTA */
  --bg: #0a0d12;
  --panel: #151a21;
  --text: #e8f1f8;
  --muted: #8b9cb0;
  --accent: #ff7b29;  /* Arancione primario */
  --accent-2: #29c7ac; /* Verde/Azzurro secondario */
  --system: #4c78ff;   /* Blu per messaggi sistema */
  --danger: #ff4444;   /* Rosso per azioni distruttive */
  
  /* Variabili Neon aggiornate */
  --neon-o: 0 0 18px rgba(255, 123, 41, 0.45), 0 0 36px rgba(255, 123, 41, 0.25);
  --neon-c: 0 0 18px rgba(41, 199, 172, 0.45), 0 0 36px rgba(41, 199, 172, 0.25);
  --neon-s: 0 0 18px rgba(76, 120, 255, 0.45), 0 0 36px rgba(76, 120, 255, 0.25);
}

/* FIX PER FIREFOX/LINUX MINT DARK MODE */
@-moz-document url-prefix() {
  :root {
    --bg: #0d1117;
    --text: #e6edf3;
  }
}

@supports (height: 100dvh) {
  :root {
    --vh: 100dvh;
  }
}

/* Sfondo Personalizzato */
body[style*="--bg-image"] {
  background-image: var(--bg-image);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}
body[style*="--bg-image"] .sidebar,
body[style*="--bg-image"] .toolbar,
body[style*="--bg-image"] .mbar,
body[style*="--bg-image"] .composer,
body[style*="--bg-image"] dialog {
  background: var(--panel);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Temi */
:root[data-theme="tech"] {
  --bg: #0b0f12;
  --accent: #ff8a3d;
  --text: #e8edf2;
}
:root[data-theme="domestic"] {
  --bg: #101214;
  --accent: #59c18d;
  --text: #f1f4f6;
}
:root[data-theme="futuristic"] {
  --bg: #0a0d12;
  --accent: #00c2ff;
  --text: #e6f7ff;
  --panel: rgba(17, 21, 25, 0.7);
  --text-glow: 0 0 4px rgba(0, 194, 255, .5);
}
:root[data-theme="futuristic"] body {
  background: #0a0d12 linear-gradient(0deg, rgba(0,194,255,.03) 1px, transparent 1px) 0 0/100% 30px;
}
:root[data-theme="futuristic"] .brand strong,
:root[data-theme="futuristic"] .welcome h1,
:root[data-theme="futuristic"] .pill {
  text-shadow: var(--neon-c);
}
:root[data-theme="minimal"] {
  --bg: #0e1012;
  --accent: #cfcfcf;
  --text: #e9ecef;
}
:root[data-theme="light"] {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #181c20;
  --muted: #5a6470;
  --accent: #d9480f;
  --accent-2: #007bff;
  --neon-o: 0 0 10px rgba(217, 72, 15, .15);
  --neon-c: 0 0 12px rgba(0, 123, 255, .3);
}

/* =============================================
   2. RESET BASE E TIPOGRAFIA
   ============================================= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: var(--vh);
  overflow: hidden;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Tipografia */
h1, h2, h3 {
  font-weight: 800;
  margin-bottom: 0.5em;
}
h1 { font-size: 1.75em; }
h2 { font-size: 1.25em; }
p, small { margin-bottom: 0.75em; }
small {
  font-size: 0.85em;
  color: var(--muted);
}
a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* Form Elements */
button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  border: none;
  outline: none;
  background: none;
  color: inherit;
}
button { cursor: pointer; transition: all 0.2s ease; }
input, textarea, select {
  background: #12171d;
  border: 1px solid #26303a;
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius);
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: var(--neon-c);
}
textarea { resize: vertical; }

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #26303a;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* =============================================
   3. LAYOUT PRINCIPALE (MOBILE-FIRST)
   ============================================= */
body {
  display: flex;
  flex-direction: column;
  min-height: var(--vh);
  transition: all 0.3s ease; /* FIX: Transizione smooth */
}

/* Main */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  min-height: 0;
  transition: margin-left 0.3s ease, width 0.3s ease; /* FIX: Transizione sidebar */
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: -280px;
  width: 280px;
  height: var(--vh);
  background: #111418;
  border-right: 1px solid #222;
  overflow-y: auto;
  transition: left 0.3s ease;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}
.sidebar.active { left: 0; }
body.sidebar-open::after {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  backdrop-filter: blur(4px);
}

/* Mobile Bar (PATCH 3) */
.mbar {
  display: flex;
  justify-content: space-around; /* Spazio equo */
  align-items: stretch; /* Altezza piena */
  padding: 4px 8px;
  padding-bottom: calc(4px + var(--safe-bottom)); /* Padding sicuro in basso */
  background: #0d1217;
  border-top: 1px solid #1b222a;
  position: fixed;
  bottom: 0; /* Attaccato in fondo */
  left: 0;
  right: 0;
  z-index: 100;
  height: calc(56px + var(--safe-bottom)); /* Altezza fissa */
}
.mbar-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10px; /* Testo piccolo */
  color: var(--muted);
  border-radius: 8px;
}
.mbar-btn .icon {
  font-size: 20px; /* Icona grande */
}
.mbar-btn:hover, .mbar-btn.active {
  background: #181e25;
  color: var(--accent);
}

/* =============================================
   4. COMPONENTI COMUNI
   ============================================= */

/* Pills */
.pill {
  padding: 8px 16px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #111;
  font-weight: 600;
  border: none;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.pill:hover {
  transform: translateY(-1px);
  box-shadow: var(--neon-o);
}
.pill.ghost {
  background: transparent;
  border: 1px solid #26303a;
  color: var(--text);
}
.pill.ghost:hover {
  border-color: var(--accent);
  box-shadow: var(--neon-c);
  background: rgba(0, 194, 255, 0.1);
}
.pill.subtle { opacity: 0.7; }

/* Chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  background: #12171d;
  border: 1px solid #26303a;
  color: var(--text);
  font-size: 0.85em;
  cursor: pointer;
  transition: all 0.2s;
}
.chip:hover { border-color: var(--accent); }

/* Progress */
.ctx-progress {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ctx-progress .bar {
  height: 6px;
  background: #1d232a;
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.ctx-progress #ctxUsed {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.35s ease;
}
.ctx-progress .mark70 {
  position: absolute;
  top: 0;
  left: 70%;
  width: 1px;
  height: 100%;
  background: var(--muted);
}
.ctx-progress {
  margin-top: 8px;
}
.ctx-progress .bar {
  height: 8px;
  border-radius: 4px;
  background: #1a1a1a;
  overflow: hidden;
  position: relative;
}
.ctx-progress .bar #ctxUsed {
  background: linear-gradient(90deg, #ff7b00, #ffb100);
  height: 100%;
  width: 0%;
  transition: width .3s ease;
}
.ctx-progress .meta {
  font-weight: 600;
  font-size: 0.95em;
  margin-top: 6px;
  text-align: right;
}


/* Toasts */
.toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 16px;
  border-radius: 8px;
  background: #12171d;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  animation: toastIn 0.3s ease;
  max-width: 300px;
}
.toast.err { background: #522; color: #fdd; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Banner */
.banner {
  padding: 12px;
  background: #1a1f26;
  border: 1px solid #26303a;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px;
}
.banner-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Spinner */
.spinner {
  display: flex;
  gap: 4px;
  padding: 8px;
}
.spinner .dot {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: dotPulse 1.4s infinite ease-in-out;
}
.spinner .dot:nth-child(1) { animation-delay: -0.32s; }
.spinner .dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes dotPulse {
  0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* =============================================
   5. SIDEBAR
   ============================================= */
.side-head {
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #1b222a;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.brand strong {
  font-size: 1.25em;
  font-weight: 800;
}
.brand small {
  display: block;
  font-size: 0.75em;
  opacity: 0.7;
}

.auth-cta, .auth-status {
  display: flex;
  gap: 6px;
  align-items: center;
}
.auth-status strong {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.auth-status .pill { font-size: 0.8em; padding: 4px 8px; }

.side-sec {
  flex: 1;
  padding: 0 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.side-links {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.persona-panel {
  margin: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.persona-panel label {
  font-weight: 600;
  font-size: 0.9em;
}


.side-title {
  font-weight: 600;
  opacity: 0.9;
  margin: 12px 0 8px 0;
  font-size: 0.95em;
}

.side-search {
  display: flex;
  gap: 8px;
  margin: 8px 0;
}
.side-search input {
  flex: 1;
  padding: 10px 12px;
}
.side-search button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.conv-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}
.conv {
  padding: 12px;
  border: 1px solid #26303a;
  background: #181e25;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  position: relative;
}
.conv:hover, .conv.active {
  background: #1e252e;
  border-color: var(--accent);
  box-shadow: var(--neon-c);
}
.conv .title {
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 20px;
}
.conv .snippet, .conv small {
  font-size: 0.8em;
  opacity: 0.7;
  color: var(--muted);
}
.conv .delete-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255, 0, 0, 0.1);
  color: #ff6b6b;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  opacity: 0;
  transition: all 0.2s;
}
.conv:hover .delete-btn {
  opacity: 1;
}
.conv .delete-btn:hover {
  background: rgba(255, 0, 0, 0.2);
  transform: scale(1.1);
}

.pro-card {
  padding: 16px;
  border: 1px solid #27313b;
  border-radius: var(--radius);
  background: #11161c;
}
.pro-title {
  font-weight: 700;
  margin-bottom: 8px;
}
.pro-points {
  list-style: none;
  margin: 8px 0;
  padding-left: 0;
}
.pro-points li {
  padding: 4px 0;
  font-size: 0.9em;
  position: relative;
  padding-left: 20px;
}
.pro-points li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--accent);
}
.pro-card .small-cta {
  display: block;
  margin-top: 12px;
  font-size: 0.8em;
}

/* =============================================
   7. WELCOME BANNER
   ============================================= */

/* =============================================
   PATCH 3: Stile per Nuova Toolbar Orizzontale - MIGLIORATA
   ============================================= */
.toolbar.desk-only {
  padding: 16px 24px 20px 24px;
  border-bottom: 1px solid #1b222a;
  background: var(--bg);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  align-items: start;
  padding-left: 64px;
}

/* Titoli più evidenti */
.toolbar .side-title {
  font-size: 1.1em;
  font-weight: 800;
  margin-bottom: 8px;
  color: var(--accent);
}

/* Barra memoria più prominente */
.toolbar .ctx-progress .bar {
  height: 12px;
  border-radius: 6px;
  background: #1a1a1a;
}

.toolbar .ctx-progress .meta {
  font-size: 1.1em;
  font-weight: 700;
  margin-top: 8px;
}

/* Argomento più evidente */
.toolbar .topic-value-editable {
  font-size: 1.2em;
  font-weight: 700;
  padding: 12px;
  border: 2px solid transparent;
}

.toolbar .topic-value-editable:focus {
  border-color: var(--accent);
  background: rgba(0, 194, 255, 0.05);
}

/* Tooltip per descrizione tecnica */
.tooltip-info {
  position: relative;
  display: inline-block;
  margin-left: 8px;
  cursor: help;
}

.tooltip-info::after {
  content: "ℹ️";
  font-size: 0.9em;
  opacity: 0.7;
}

.tooltip-info:hover::before {
  content: "Questa è la mia memoria per questa chat. Quando sarà piena inizierò a fare dei riassunti e qualcosa potrei non ricordarlo.";
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #12171d;
  color: var(--text);
  padding: 12px;
  border-radius: 8px;
  font-size: 0.85em;
  white-space: nowrap;
  z-index: 1000;
  border: 1px solid #26303a;
  width: 280px;
  white-space: normal;
}
/* =============================================
   MANIFESTO BANNER
   ============================================= */
.manifesto-banner {
  padding: 20px 16px;
  background: linear-gradient(135deg, #0d1217 0%, #1a1f26 100%);
  border-bottom: 1px solid #1b222a;
  text-align: center;
}

.manifesto-content h2 {
  font-size: 1.4em;
  margin-bottom: 8px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.manifesto-content p {
  max-width: 600px;
  margin: 0 auto 16px auto;
  opacity: 0.9;
}

.manifesto-links {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.manifesto-links .pill {
  font-size: 0.85em;
  padding: 6px 12px;
}
/* =============================================
   8. CHAT AREA
   ============================================= */

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 100px 20px; /* Più spazio */
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 24px; /* Più spazio tra messaggi */
  scrollbar-gutter: stable;
}
.chat-tools {
  display: flex;
  justify-content: center;
  padding: 8px;
}
.chat-tools button {
  padding: 6px 12px;
  font-size: 0.85em;
}

.msg {
  max-width: 80%;
  padding: 20px; /* Più padding */
  border-radius: var(--radius);
  animation: msgSlideIn 0.3s ease-out;
  position: relative;
  word-wrap: break-word;
  line-height: 1.6; /* Migliore interlinea */
}

.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}
.msg.assistant {
  align-self: flex-start;
  /* PATCH: Background più chiaro per staccare dal fondo (come da report) */
  background: #181e25; 
  border: 1px solid #26303a;
}
.msg .role {
  font-size: 0.75em;
  opacity: 0.7;
  margin-bottom: 8px;
  text-transform: uppercase;
  font-weight: 600;
}
.msg .content {
  line-height: 1.6; /* Interlinea migliorata */
  font-size: 1.05em; /* Leggermente più grande */
}
.msg.generating .content::after {
  content: '█';
  animation: blink 1s step-end infinite;
  margin-left: 2px;
  color: currentColor;
}
@keyframes blink {
  50% { opacity: 0; }
}
.msg .tools {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.msg .tools:hover {
  opacity: 1;
}
.msg .tools button {
  font-size: 0.75em;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
}
.msg .tools button:hover {
  background: rgba(255, 255, 255, 0.2);
}
@keyframes msgSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.typing {
  align-self: flex-start;
  padding: 12px 16px;
  background: #12171d;
  border-radius: var(--radius);
  border: 1px solid #26303a;
  display: flex;
  gap: 4px;
}
.typing .dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: dotBounce 1.2s infinite;
}
.typing .dot:nth-child(2) { animation-delay: 0.2s; }
.typing .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBounce {
  0%, 60%, 100% { transform: scale(1); }
  30% { transform: scale(0.5); }
}

.ctxbox {
  margin: 16px;
  background: #0d1217;
  border: 1px solid #26303a;
  border-radius: var(--radius);
}
.ctxbox summary {
  padding: 12px;
  cursor: pointer;
  font-weight: 600;
  border-bottom: 1px solid #26303a;
}
#ctxView {
  padding: 16px;
  background: #111;
  font-family: monospace;
  font-size: 0.8em;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
}
/* PATCH: Stile per il timestamp del messaggio (Proposta B report) */
.msg .msg-time {
  font-size: 0.75em;
  color: var(--muted);
  position: absolute;
  top: 10px; /* Allinea con il padding */
  right: 16px;
  opacity: 0.8;
}

.msg.user .msg-time {
  color: rgba(255, 255, 255, 0.7); /* Meno invadente su bolla utente */
}

/* Sposta il ruolo a sinistra per fare spazio al tempo */
.msg .role {
  margin-right: 60px; /* Spazio per il tempo */
}
/* =============================================
   9. COMPOSER
   ============================================= */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 12px; /* Più spazio */
  padding: 16px 20px; /* Più padding */
  background: var(--panel);
  border-top: 1px solid #1b222a;
  position: fixed;
  bottom: var(--safe-bottom);
  left: 0;
  right: 0;
  z-index: 90;
  backdrop-filter: blur(8px);
}
.composer button.ghost {
  /* PATCH: Aumenta la dimensione per accessibilità mobile (min 48px) */
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid #26303a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all 0.2s;
  flex-shrink: 0;
}
.composer button.ghost:hover {
  border-color: var(--accent);
  box-shadow: var(--neon-c);
  background: rgba(0, 194, 255, 0.1);
}
.composer button.ghost.spinning {
  animation: spin 1s linear infinite;
}
.composer button.ghost:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.composer button.ghost:disabled:hover {
  border-color: #26303a;
  box-shadow: none;
  background: transparent;
}
#selfDestructMsgBtn.on {
  background: #522;
  border-color: #a44;
  color: #fdd;
}
#send {
  /* PATCH: Aumenta la dimensione per accessibilità mobile */
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: all 0.2s;
}
#send:hover {
  transform: scale(1.05);
  box-shadow: var(--neon-o);
}
#send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.composer textarea {
  flex: 1;
  min-height: 52px; /* Più alto */
  max-height: 150px; /* Più spazio per testo lungo */
  padding: 12px 16px; /* Più padding interno */
  border: 2px solid #26303a; /* Bordo più spesso */
  border-radius: 12px; /* Angoli più arrotondati */
  resize: none;
  line-height: 1.5;
  font-size: 1.05em; /* Testo più grande */
  transition: border-color 0.2s, box-shadow 0.2s;
}
.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--neon-c);
  background: rgba(0, 194, 255, 0.02);
}
#send {
  width: 52px; /* Leggermente più grande */
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px; /* Icona più grande */
  flex-shrink: 0;
  transition: all 0.2s;
  position: relative;
}

#send:hover::after {
  content: "Invia";
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: #12171d;
  color: var(--text);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8em;
  white-space: nowrap;
  border: 1px solid #26303a;
}
/* =============================================
   10. DIALOGS E MODALI
   ============================================= */
dialog {
  border: none;
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 16px 48px rgba(0,0,0,0.4);
  max-width: 90vw;
  width: 500px;
  max-height: 90vh;
  overflow: hidden;
  display: none;
  flex-direction: column;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2100;
}
dialog[open] {
  display: flex;
}
/* Sfondo solido per Auth e Debug */
#authDialog, #debugPanel {
  background: var(--bg);
  border: 1px solid #26303a;
}

.panel-dialog {
  width: 100vw;
  height: var(--vh);
  max-width: none;
  border-radius: 0;
  max-height: none;
  top: 0;
  left: 0;
  transform: none;
  z-index: 2000;
}
.panel-dialog .tabs {
  flex-shrink: 0;
  display: flex;
  gap: 0;
  border-bottom: 1px solid #26303a;
  overflow-x: auto;
}
.tabpane {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: none;
}
.tabpane.on { display: block; }
.tab {
  flex: 1;
  padding: 12px 16px;
  text-align: center;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  cursor: pointer;
  background: transparent;
  color: var(--text);
}
.tab.on {
  border-bottom-color: var(--accent);
  background: rgba(0, 194, 255, 0.05);
}

.pers-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
.pers-grid .full-width { grid-column: 1 / -1; }
@media (min-width: 600px) {
  .pers-grid { grid-template-columns: 1fr 1fr; }
}
.pers-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9em;
  font-weight: 600;
}
.pers-grid input, .pers-grid select, .pers-grid textarea {
  font-size: 0.9em;
}

.check-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid #26303a;
  border-radius: var(--radius);
  padding: 12px;
  background: #12171d;
}
.check-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9em;
  cursor: pointer;
}
.check-grid input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.bias-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.bias-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}
.bias-presets .pill {
  font-size: 0.8em;
  padding: 6px 10px;
}
.bias-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
  background: #12171d;
  border: 1px solid #26303a;
  border-radius: var(--radius);
}
.bias-label {
  font-size: 0.85em;
  cursor: help;
}
.bias-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.bias-controls button {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #26303a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.bias-controls button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
.bias-val {
  font-weight: 600;
  min-width: 20px;
  text-align: center;
}
.bias-val.pos { color: #00c2ff; }
.bias-val.neg { color: #ff8a3d; }
.bias-val.zero { color: var(--muted); }

.dialog-actions {
  padding: 16px;
  border-top: 1px solid #26303a;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  flex-shrink: 0;
}

/* Pro Features */
.pro-feature[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
.pro-feature[disabled] ~ * { opacity: 0.5; }

/* Auth Grid */
.auth-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 16px 0;
}
.auth-grid .divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}
.auth-grid .divider::before,
.auth-grid .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #26303a;
}
.auth-grid .row {
  display: flex;
  gap: 8px;
}
.auth-grid .pill.wide {
  width: 100%;
  justify-content: center;
}


/* =============================================
   12. FOOTER
   ============================================= */
.foot {
  padding: 12px 16px;
  background: #0d1217;
  border-top: 1px solid #1b222a;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85em;
  position: relative;
  z-index: 10;
}
.foot #status {
  color: var(--accent);
}
.foot .muted {
  color: var(--muted);
}

/* =============================================
   13. MEDIA QUERIES (RESPONSIVE)
   ============================================= */
@media (min-width: 901px) {
  body {
    flex-direction: row;
  }
  .mbar { display: none; }
  .sidebar {
    position: sticky;
    left: 0;
    height: var(--vh);
    flex-shrink: 0; /* Aggiunto per sicurezza */
    transform: translateX(0);
    transition: transform 0.3s ease; /* Transizione sul transform */
  }
  body.sidebar-desk-closed .sidebar {
    transform: translateX(-100%); /* Metodo più affidabile */
  }
  .main {
    width: calc(100% - 280px);
    margin-left: 280px;
  }
  body.sidebar-desk-closed .main {
    width: 100%;
    margin-left: 0;
  }
  .composer {
    left: 280px;
    width: calc(100% - 280px);
  }
  body.sidebar-desk-closed .composer {
    left: 0;
    width: 100%;
  }
  .chat {
    padding: 24px;
    gap: 20px;
  }
  .welcome {
    padding: 40px 10%;
    max-width: 800px;
    margin: 0 auto;
  }
  dialog { width: 600px; max-height: 80vh; }
  .pers-grid { grid-template-columns: 1fr 1fr; }
  .chat-action-toolbar { right: 24px; }
  
  /* ERRORE: Questa riga (sotto) spaccava i pulsanti-pillola. L'ho rimossa. */
  /* .chat-action-toolbar .pill { width: 56px; height: 56px; font-size: 20px; } */

  .foot {
    position: sticky;
    bottom: 0;
  }
}

@media (max-width: 900px) {
  .desk-only { display: none !important; }
  .foot {
    position: fixed;
    bottom: 60px; /* Sopra la mbar */
    left: 0;
    right: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
/* =============================================
   PATCH 3: Stile per Nuova Toolbar Orizzontale
   ============================================= */
.toolbar.desk-only {
  padding: 12px 16px 16px 16px;
  border-bottom: 1px solid #1b222a;
  background: var(--bg);
  display: grid;
  grid-template-columns: 1fr 1fr; /* Due colonne eque */
  gap: 24px;
  align-items: start;
  /* Spazio per il bottone hamburger ☰ */
  padding-left: 64px; 
}

/* Rimuovi stili specifici della sidebar (bordi, padding) */
.toolbar .side-group {
  border-bottom: none;
  padding: 0;
}
.toolbar .side-group .side-title {
  padding-top: 0;
}

/* Stile Light Mode per la nuova toolbar */
:root[data-theme="light"] .toolbar.desk-only {
  border-color: #dfe3e8;
}
/* =============================================
   PATCH 3: STILI PER SIDEBAR CONSOLIDATA
   ============================================= */
.side-actions {
  display: flex;
  gap: 8px;
  padding: 16px;
  border-bottom: 1px solid #1b222a;
}
.side-actions .pill {
  flex: 1;
  text-align: center;
  padding: 10px 8px; /* Più spazio verticale */
}

.side-group {
  padding: 0 16px 16px 16px;
  border-bottom: 1px solid #1b222a;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.side-group .side-title {
  margin: 0; /* Rimuove il margine di default */
  padding-top: 12px;
}

/* Stile per l'argomento modificabile */
.topic-value-editable {
  font-weight: 600;
  color: var(--accent);
  padding: 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}
.topic-value-editable:hover {
  border-color: #26303a;
  background: #12171d;
}
.topic-value-editable:focus {
  border-color: var(--accent);
  background: #12171d;
  outline: none;
  box-shadow: var(--neon-c);
}

/* Stili per la nuova toolbar statica */
#staticChatToolbar {
  border-bottom: none; /* Niente bordo extra in fondo */
}
#staticChatToolbar .pill {
  text-align: left; /* Allinea a sx */
  background: #12171d; /* Sfondo leggero */
  padding: 10px 12px;
  font-size: 0.9em;
}
#staticChatToolbar .pill:hover {
  background: #171d24;
  border-color: var(--accent);
}
/* Stile per nascondere i bottoni disattivati dalle Impostazioni */
#staticChatToolbar button[style*="display: none"] {
  display: none !important;
}

/* =============================================
   14. LIGHT THEME OVERRIDES (COMPLETO)
   ============================================= */
:root[data-theme="light"] {
  --panel: #ffffff;
}
:root[data-theme="light"] .sidebar,
:root[data-theme="light"] .toolbar,
:root[data-theme="light"] .mbar,
:root[data-theme="light"] .composer,
:root[data-theme="light"] .msg.assistant,
:root[data-theme="light"] .conv,
:root[data-theme="light"] .pro-card,
:root[data-theme="light"] .persona-panel textarea,
:root[data-theme="light"] input,
:root[data-theme="light"] textarea,
:root[data-theme="light"] select,
:root[data-theme="light"] .check-grid,
:root[data-theme="light"] .ctxbox,
:root[data-theme="light"] .banner,
:root[data-theme="light"] .chip,
:root[data-theme="light"] .bias-row,
:root[data-theme="light"] .sheet {
  background: #fff;
  border-color: #dfe3e8;
  color: #181c20;
}
:root[data-theme="light"] .side-search input,
:root[data-theme="light"] .composer textarea {
  background: #f8f9fa;
  border-color: #ced4da;
}
:root[data-theme="light"] .pill.ghost,
:root[data-theme="light"] .ghost,
:root[data-theme="light"] .sheet-btn {
  border-color: #ced4da;
  background: #f0f2f5;
  color: #333;
}
:root[data-theme="light"] .pill.ghost:hover,
:root[data-theme="light"] .sheet-btn:hover {
  background: #e9ecef;
  border-color: var(--accent-2);
}
:root[data-theme="light"] .conv:hover,
:root[data-theme="light"] .conv.active {
  background: #f8f9fa;
  border-color: #c0c8d1;
}
:root[data-theme="light"] .pro-points li::before { color: var(--accent); }
:root[data-theme="light"] small, 
:root[data-theme="light"] .muted { color: #5a6470; }
:root[data-theme="light"] .ctx-progress .bar { background: #e9ecef; }
:root[data-theme="light"] .msg .tools button {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.1);
  color: #333;
}
:root[data-theme="light"] .msg .tools button:hover {
  background: rgba(0, 0, 0, 0.1);
}
:root[data-theme="light"] .toast {
  background: #fff;
  color: #181c20;
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}
:root[data-theme="light"] .toast.err {
  background: #ffe6e6;
  color: #d00;
}
:root[data-theme="light"] .bias-controls button {
  background: #e9ecef;
  color: #333;
}
:root[data-theme="light"] .foot {
  background: #f8f9fa;
  border-color: #dfe3e8;
}
/* PATCH 3: Stili Light Mode per Sidebar consolidata */
:root[data-theme="light"] .side-actions,
:root[data-theme="light"] .side-group {
  border-color: #dfe3e8;
}
:root[data-theme="light"] .topic-value-editable:hover {
  background: #f8f9fa;
  border-color: #ced4da;
}
:root[data-theme="light"] .topic-value-editable:focus {
  background: #f8f9fa;
  border-color: var(--accent-2);
  box-shadow: none;
}
:root[data-theme="light"] #staticChatToolbar .pill {
  background: #f8f9fa;
}
:root[data-theme="light"] #staticChatToolbar .pill:hover {
  background: #f0f2f5;
}
/* =============================================
   15. PRELOADER E STATI DI CARICAMENTO
   ============================================= */
.preloader {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  gap: 16px;
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

.preloader .spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #26303a;
  border-top: 4px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

body.loaded .preloader {
  display: none;
}

/* Assicurati che la sidebar sia nascosta durante il loading */
body.loading .sidebar {
  visibility: hidden;
}

/* Mostra tutto solo quando loaded */
body.loaded .sidebar {
  visibility: visible;
}

/* =============================================
   16. UTILITY CLASSES
   ============================================= */
.hidden {
  display: none !important;
}

.collapsible {
  max-height: 200px;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.collapsible.open {
  max-height: none;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #12171d;
  border: 1px solid #26303a;
  border-radius: 20px;
  font-size: 0.85em;
  margin: 4px;
}

.attach-chip .x {
  cursor: pointer;
  padding: 2px;
  border-radius: 50%;
  transition: background 0.2s;
}

.attach-chip .x:hover {
  background: #26303a;
}

/* Sheet per mobile */
.sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--panel);
  border-top: 1px solid #26303a;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  z-index: 1000;
}

.sheet.show {
  transform: translateY(0);
}

.sheet-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sheet-btn {
  padding: 12px 16px;
  background: transparent;
  border: 1px solid #26303a;
  border-radius: var(--radius);
  color: var(--text);
  text-align: left;
  transition: all 0.2s;
}

.sheet-btn:hover {
  border-color: var(--accent);
  background: rgba(0, 194, 255, 0.1);
}

/* Dropzone */
.dropzone {
  border: 2px dashed #26303a;
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  transition: all 0.3s ease;
  cursor: pointer;
}

.dropzone.on {
  border-color: var(--accent);
  background: rgba(0, 194, 255, 0.05);
  color: var(--accent);
}

/* Tooltip */
[data-tooltip] {
  position: relative;
}

[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #12171d;
  color: var(--text);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 0.8em;
  white-space: nowrap;
  z-index: 1000;
  border: 1px solid #26303a;
}

/* =============================================
   17. ANIMATIONS EXTRA
   ============================================= */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideInUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.fade-in { animation: fadeIn 0.3s ease; }
.slide-in-up { animation: slideInUp 0.3s ease; }
.pulse { animation: pulse 2s infinite; }

/* =============================================
   18. ACCESSIBILITY
   ============================================= */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus styles per accessibilità */
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* High contrast support */
@media (prefers-contrast: high) {
  :root {
    --bg: #000000;
    --text: #ffffff;
    --accent: #00ffff;
    --accent-2: #ffff00;
  }
}

/* Print styles */
@media print {
  .mbar,
  .composer,
  .chat-action-toolbar,
  .sidebar,
  .toolbar .actions-left {
    display: none !important;
  }
  
  .main {
    margin-left: 0 !important;
    width: 100% !important;
  }
  
  body {
    background: white !important;
    color: black !important;
  }
}
/* =============================================
   FIX: DIMENSIONAMENTO ICONE SVG NEI MESSAGGI
   ============================================= */
.msg .tools svg {
  width: 14px;
  height: 14px;
  vertical-align: middle;
  margin-right: 4px;
}

/* Fix per allineare l'emoji "Leggi" (già che ci siamo) */
.msg .tools .readone {
  vertical-align: middle;
}
/* =============================================
   FIX: VISIBILITÀ TESTO IN LIGHT MODE
   ============================================= */
:root[data-theme="light"] .msg.assistant .content {
  color: #181c20; /* Forza il colore del testo nero */
}


/* 2. FIX BOTTONI LATERALI "NON PERFETTI" */
.chat-action-toolbar .pill {
  min-width: 90px;
  text-align: center;
  padding-top: 6px;    
  padding-bottom: 6px; 
}

/* 3. FIX TASTIERA MOBILE (SOVRAPPOSIZIONE COMPOSER) */
.composer {
  /* Usa la variabile JS per spostarsi sopra la tastiera */
  bottom: calc(var(--safe-bottom) + var(--keyboard-height));
  /* Aggiunge la transizione per 'bottom' */
  transition: left 0.3s ease, width 0.3s ease, bottom 0.2s ease-out;
}

/* 4. FIX SCROLL ORIZZONTALE INATTESO */
html, body {
  overflow-x: hidden;
  width: 100%;
}
.main {
  overflow-x: hidden;
}

/* 5. FIX CONTRASTO TEMA CHIARO (Accessibilità) */
:root[data-theme="light"] small, 
:root[data-theme="light"] .muted {
  color: #495057; /* Scurito per migliorare leggibilità */
}

/* deepseek FIX  */

/* =============================================
   FIX URGENTE MOBILE - NASCONDI ELEMENTI DESKTOP
   ============================================= */


/* =============================================
   FIX LAYOUT MOBILE
   ============================================= */

/* Assicura che la mbar sia sempre in fondo e visibile */
.mbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--panel);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Main content su mobile deve avere padding per la mbar */
@media (max-width: 900px) {
  .main {
    padding-bottom: 80px; /* Spazio per la mbar */
  }
  
  .chat {
    padding-bottom: 140px; /* Spazio per mbar + composer */
  }
}

/* =============================================
   FIX VISUALIZZAZIONE CHAT MOBILE
   ============================================= */

@media (max-width: 900px) {
  .chat {
    max-width: 100% !important;
    padding: 12px 8px !important;
  }
  
  .msg {
    max-width: 90% !important; /* Più spazio per i messaggi su mobile */
  }
  
  .msg.user {
    max-width: 85% !important;
  }
}

/* =============================================
   FIX Z-INDEX E SOVRAPPOSIZIONI
   ============================================= */

.mbar {
  z-index: 1000;
}

.composer {
  z-index: 999;
}

.sheet {
  z-index: 1001;
}

/* =============================================
   FIX PRELOADER MOBILE
   ============================================= */

@media (max-width: 900px) {
  .preloader {
    z-index: 9999;
  }
  
  /* Nascondi il toggle desktop */
  #sidebarToggleDesk {
    display: none !important;
  }
}

/* =============================================
   FIX TASTIERA VIRTUALE MOBILE
   ============================================= */

@media (max-width: 900px) {
  .composer {
    position: fixed;
    bottom: calc(60px + var(--safe-bottom) + var(--keyboard-height));
    transition: bottom 0.3s ease;
  }
  
  .chat {
    padding-bottom: calc(140px + var(--keyboard-height));
  }
}

@media (max-width: 900px) {
  .chat {
    padding-bottom: calc(80px + var(--safe-bottom)) !important;
  }
}
/* Assicurati che i bottoni desktop siano visibili */
@media (min-width: 901px) {
  .side-actions.desk-only {
    display: flex !important;
    gap: 8px;
    padding: 16px;
    border-bottom: 1px solid #1b222a;
  }
  
  #openPersonalize {
    display: flex !important;
  }
  
  #newChat {
    display: flex !important;
  }
}
/* =============================================
   FIX VISIBILITÀ BOTTONI DESKTOP/MOBILE
   ============================================= */

/* Desktop - mostra solo elementi desktop */
@media (min-width: 901px) {
  .desk-only {
    display: block !important;
  }
  
  .mbar {
    display: none !important;
  }
  
  .side-actions {
    display: flex !important;
  }
}

/* Mobile - mostra solo elementi mobile */
@media (max-width: 900px) {
  .desk-only {
    display: none !important;
  }
  
  .mbar {
    display: flex !important;
  }
  
  /* Assicurati che la sidebar mobile sia nascosta di default */
  .sidebar {
    display: none;
  }
  
  .sidebar.active {
    display: flex;
  }
}

/* Stile per i bottoni della sidebar desktop */
.side-actions {
  display: flex;
  gap: 8px;
  padding: 16px;
  border-bottom: 1px solid #1b222a;
}

.side-actions .pill {
  flex: 1;
  text-align: center;
}



/* =============================================
   FIX BOTTONI PERSONALIZZA E NUOVA CHAT
   ============================================= */

/* Assicura che i bottoni esistano e siano cliccabili */
#newChat, #openPersonalize, #mPersonalize {
  cursor: pointer;
}

/* Stile per i bottoni della sidebar */
.side-actions {
  display: flex;
  gap: 8px;
  padding: 16px;
  border-bottom: 1px solid #1b222a;
}

.side-actions .pill {
  flex: 1;
  text-align: center;
  padding: 10px 16px;
}
/* =============================================
   FIX LAYOUT DEFINITIVO (SOSTITUISCE TUTTI I PATCH)
   ============================================= */

/* 1. LAYOUT DESKTOP (Default da 901px in su) */
@media (min-width: 901px) {

  /* Nascondi la barra mobile */
  .mbar {
    display: none !important;
  }
  
  /* Mostra gli elementi solo-desktop */
  .desk-only,
  .side-actions.desk-only {
    display: flex !important;
    visibility: visible !important;
  }

  /* Sidebar: visibile di default */
  .sidebar {
    display: flex !important;
    position: sticky !important;
    top: 0 !important;
    left: 0 !important;
    transform: translateX(0) !important;
    visibility: visible !important;
    transition: transform 0.3s ease !important;
  }
  
  /* Main: spostato di default */
  .main {
    width: calc(100% - 280px) !important;
    margin-left: 280px !important;
    transition: margin-left 0.3s ease, width 0.3s ease !important;
  }
  
  /* Composer: spostato di default */
  .composer {
    left: 280px !important;
    width: calc(100% - 280px) !important;
    transition: left 0.3s ease, width 0.3s ease !important;
  }

  /* STATO CHIUSO: Quando il body ha la classe (gestita da JS) */
  
  body.sidebar-desk-closed .sidebar {
    transform: translateX(-100%) !important;
  }
  
  body.sidebar-desk-closed .main {
    width: 100% !important;
    margin-left: 0 !important;
  }
  
  body.sidebar-desk-closed .composer {
    left: 0 !important;
    width: 100% !important;
  }
}

/* 2. LAYOUT MOBILE (Fino a 900px) */
@media (max-width: 900px) {

  /* Nascondi elementi solo-desktop */
  .desk-only {
    display: none !important;
  }
  
  /* Mostra la barra mobile */
  .mbar {
    display: flex !important;
  }
  
  /* Sidebar: nascosta di default */
  .sidebar {
    display: none;
    position: fixed;
    z-index: 1000;
  }
  
  /* Sidebar: mostrata solo se 'attiva' (per il toggle mobile) */
  .sidebar.active {
    display: flex;
  }
  
  /* Main e Composer: occupano tutto lo spazio */
  .main,
  body.sidebar-desk-closed .main {
    width: 100% !important;
    margin-left: 0 !important;
  }
  
  .composer,
  body.sidebar-desk-closed .composer {
    left: 0 !important;
    width: 100% !important;
  }
}
/* =============================================
   FIX ALTERNATIVO (IL MARTELLO)
   ============================================= */

@media (min-width: 901px) {
  
  /* STATO APERTO (DEFAULT) */
  body:not(.sidebar-desk-closed) .main {
    width: calc(100% - 280px) !important;
    margin-left: 280px !important;
  }
  
  body:not(.sidebar-desk-closed) .composer {
    left: 280px !important;
    width: calc(100% - 280px) !important;
  }
  
  body:not(.sidebar-desk-closed) .sidebar {
    transform: translateX(0) !important;
  }

  /* STATO CHIUSO (QUANDO CLICCHI ☰) */
  body.sidebar-desk-closed .main {
    width: 100% !important;
    margin-left: 0 !important;
  }

  body.sidebar-desk-closed .composer {
    left: 0 !important;
    width: 100% !important;
  }
  
  body.sidebar-desk-closed .sidebar {
    transform: translateX(-100%) !important;
  }
}
@media (min-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    background: var(--bg-side);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    transform: translateX(0);
    z-index: 100;
    box-shadow: 2px 0 8px rgba(0,0,0,0.2);
  }

  .main {
    margin-left: 280px;
    transition: margin-left 0.3s ease;
  }

  body.sidebar-desk-closed .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }

  body.sidebar-desk-closed .main {
    margin-left: 0;
  }
}
/* === FIX UI 2025 — Correzione conflitti pulsanti e layout === */

/* --- Pulsanti coerenti (pill + ghost) --- */
.pill {
  display: inline-block;
  border-radius: 20px;
  padding: 6px 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border 0.2s;
  text-align: center;
  user-select: none;
}

.pill:not(.ghost) {
  background: var(--accent, #4cafef);
  border: none;
  color: #fff;
}

.pill:not(.ghost):hover {
  background: color-mix(in srgb, var(--accent, #4cafef) 80%, #000);
}

.pill.ghost {
  background: transparent;
  border: 1px solid var(--accent, #4cafef);
  color: var(--accent, #4cafef);
}

.pill.ghost:hover {
  background: var(--accent, #4cafef);
  color: #fff;
}

/* --- Barra mobile e pulsanti desktop --- */
.mbar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: space-around;
  background: rgba(20, 24, 28, 0.9);
  backdrop-filter: blur(6px);
  padding: 6px 0;
  z-index: 2000;
}

.mbar-btn {
  flex: 1;
  text-align: center;
  font-size: 13px;
  color: var(--text, #fff);
  background: none;
  border: none;
}

.mbar-btn:hover {
  color: var(--accent, #4cafef);
}

/* --- Pulsante menu desktop --- */
#sidebarToggleDesk {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 2000;
}

/* --- Media query: mobile/desktop switch --- */
@media (max-width: 767px) {
  .desk-only { display: none !important; }
  .mbar { display: flex !important; }
}

@media (min-width: 768px) {
  .desk-only { display: block !important; }
  .mbar { display: none !important; }
}

/* --- Prevenzione overlay chat --- */
.sidebar,
.welcome,
.chat,
.main {
  z-index: auto;
}

/* --- Migliore evidenza per “Nuova Chat” e “Personalizza” --- */
#newChat, #openPersonalize {
  background: var(--accent, #4cafef);
  color: #fff;
  border: none;
}

#newChat:hover, #openPersonalize:hover {
  background: color-mix(in srgb, var(--accent, #4cafef) 80%, #000);
}
/* === FIX Desktop Buttons === */
@media (min-width: 768px) {
  #newChat, #openPersonalize, #sidebarToggleDesk {
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
}
/* === FIX Mobile Chat Layout === */
@media (max-width: 767px) {
  .chat {
    display: flex;
    flex-direction: column;
    height: 100vh;
  }
  .messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding-bottom: 70px; /* spazio per l'input */
  }
  .chat-input {
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    background: #111;
    padding: 8px;
    border-top: 1px solid #333;
  }
}
/* === FIX Spacing Consistency === */
button, .pill, .mbar-btn {
  border-radius: 8px !important;
  padding: 8px 14px !important;
}
.chat, .messages {
  scroll-behavior: smooth;
}
/* === FIX UI DESKTOP & MOBILE 2025.11 === */

/* Ripristina pulsanti su desktop */
@media (min-width: 768px) {
  #newChat, #openPersonalize, #sidebarToggleDesk {
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  .sidebar-desk-closed #newChat,
  .sidebar-desk-closed #openPersonalize {
    opacity: 1 !important;
    pointer-events: auto !important;
  }
}

/* Forza la barra mobile a non influenzare desktop */
@media (min-width: 768px) {
  .mbar, .mbar-btn {
    display: none !important;
  }
}

/* Ottimizza layout chat mobile */
@media (max-width: 767px) {
  .chat {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
  }

  .messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding-bottom: 80px !important; /* spazio per input */
  }

  .chat-input, .composer {
    position: sticky;
    bottom: 0;
    background: #0e0e0e;
    border-top: 1px solid #333;
    padding: 10px;
    z-index: 3000;
  }

  input, textarea {
    width: 100%;
    border-radius: 6px;
  }
}

/* Spaziatura e pulsanti coerenti */
button, .pill, .mbar-btn {
  border-radius: 8px !important;
  padding: 8px 14px !important;
  font-weight: 600;
  transition: background 0.2s, color 0.2s;
}

/* Contrasto ottimizzato per i pulsanti arancioni */
button, .pill {
  background: #ff7b29;
  color: #fff;
  border: none;
}
button:hover, .pill:hover {
  background: #e56b1e;
}
/* === M.A.R.C.O. UI PATCH v2025.11.02-FIX === */
/* Migliora transizioni, area input e bilanciamento interfaccia */

/* --- Transizione morbida tra stati desktop/mobile --- */
body, .chat, .sidebar, .mbar, .composer, .chat-input {
  transition: all 0.25s ease-in-out !important;
}

/* --- Area input sempre visibile e centrata --- */
.chat-input, .composer {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 10px;
  padding: 12px 14px;
  background: #0f0f0f;
  border-top: 1px solid #2a2a2a;
  position: sticky;
  bottom: 0;
  z-index: 3000;
}

/* Evita che la tastiera mobile spinga fuori l’input */
@supports (-webkit-touch-callout: none) {
  .chat-input {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
  }
}

/* --- Campo testo bilanciato e leggibile --- */
.chat-input input[type="text"],
.chat-input textarea {
  flex: 1;
  width: 100%;
  min-height: 38px;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 15px;
  background: #1a1a1a;
  color: #fff;
  border: 1px solid #333;
  resize: none;
}

/* --- Pulsante di invio e allegati --- */
.chat-input button,
.chat-input .mbar-btn {
  flex-shrink: 0;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 600;
  background: #ff7b29;
  color: #fff;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}
.chat-input button:hover,
.chat-input .mbar-btn:hover {
  background: #e86a18;
}

/* --- Ottimizzazioni mobile --- */
@media (max-width: 767px) {
  .chat {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
  }

  .messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 10px;
    padding-bottom: 100px !important; /* spazio extra per input */
  }

  .chat-input {
    background: #0e0e0e;
    border-top: 1px solid #2b2b2b;
    height: auto;
  }

  /* Pulsanti in basso centrati */
  .mbar {
    display: flex !important;
    justify-content: space-around;
    align-items: center;
    padding: 6px 0;
    background: #0d0d0d;
    border-top: 1px solid #222;
  }
}

/* --- Desktop: ripristino elementi nascosti --- */
@media (min-width: 768px) {
  #newChat, #openPersonalize, #sidebarToggleDesk {
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }
  .mbar, .mbar-btn {
    display: none !important;
  }
}

/* --- Effetti visivi extra --- */
button, .pill {
  border-radius: 8px !important;
  padding: 8px 14px !important;
  font-weight: 600;
  background: #ff7b29;
  color: #fff;
  border: none;
}
button:hover, .pill:hover {
  background: #e56b1e;
}
/* === M.A.R.C.O. Layout Hotfix v2025.11.02b === */

/* Sidebar sempre scrollabile e visibile */
.sidebar {
  width: 260px !important;
  min-width: 240px !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  background: #0b0b0b !important;
  border-right: 1px solid #222 !important;
  z-index: 1000 !important;
}

/* Pulsanti sidebar sempre leggibili */
.sidebar button, .sidebar a, .sidebar .pill {
  color: #fff !important;
  font-size: 14px !important;
}

/* Corregge scrollbar invisibile */
.sidebar::-webkit-scrollbar {
  width: 6px;
}
.sidebar::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 3px;
}

/* Chat area riadattata */
.chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto !important;
  padding: 10px 12px 80px 12px !important;
}

/* Barra inferiore stabile anche con tastiera mobile */
.chat-input {
  position: fixed !important;
  bottom: 0;
  left: 0;
  right: 0;
  background: #0e0e0e !important;
  padding: 8px 12px !important;
  border-top: 1px solid #222 !important;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 4000 !important;
}

/* Campo testo bilanciato */
.chat-input textarea {
  flex: 1;
  border-radius: 8px;
  background: #1a1a1a;
  color: #fff;
  border: 1px solid #333;
  min-height: 40px;
  resize: none;
  font-size: 15px;
  padding: 8px 10px;
}

/* Pulsante invio migliorato */
.chat-input button {
  background: #ff7b29;
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  padding: 9px 14px;
  cursor: pointer;
  transition: background 0.2s;
}
.chat-input button:hover { background: #e86a18; }

/* === MOBILE FIX === */
@media (max-width: 767px) {

  /* Sidebar a comparsa */
  .sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    width: 240px !important;
  }
  .sidebar.active { transform: translateX(0) !important; }

  /* Pulsante menu visibile */
  #sidebarToggle,
  #sidebarToggleDesk {
    display: inline-flex !important;
    visibility: visible !important;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 5000;
    background: #ff7b29;
    color: white;
    border-radius: 6px;
    padding: 6px 10px;
  }

  /* Nasconde scroll doppio */
  body, html {
    overflow-x: hidden !important;
  }

  /* Barra inferiore responsive */
  .chat-input {
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Pulsanti azioni (Chat, Personalizza, Azioni) */
  .mbar {
    display: flex !important;
    justify-content: space-around;
    align-items: center;
    background: #0d0d0d;
    border-top: 1px solid #222;
    position: fixed;
    bottom: 0;
    width: 100%;
    height: 52px;
    z-index: 3500;
  }
  .mbar-btn {
    flex: 1;
    text-align: center;
    padding: 8px;
    color: #fff;
    font-size: 14px;
  }

  /* Menu toggle corretti */
  .panel {
    display: none !important;
  }
  .panel.active {
    display: block !important;
  }

  /* Forza visibilità Personalizza */
  #customizePanel, #chatPanel, #actionsPanel {
    visibility: visible !important;
    opacity: 1 !important;
  }
}
/* === FIX 2025.11 - Mobile Panels Visibility === */
.panel {
  display: none;
  animation: fadeIn 0.3s ease;
}
.panel.active {
  display: block;
}
/* === Panels Fix === */
.mbar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: #0d0d0d;
  border-top: 1px solid #222;
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 56px;
  z-index: 4000;
}
.mbar-btn {
  flex: 1;
  color: #fff;
  font-size: 13px;
  border: none;
  background: none;
  cursor: pointer;
}
.mbar-btn.active {
  color: #ff7b29;
}
.panel {
  display: none;
  position: relative;
  z-index: 3000;
  background: #0e0e0e;
  color: #fff;
  padding: 15px;
  animation: fadeIn 0.3s ease;
}
.panel.active {
  display: block;
}
@keyframes fadeIn {
  from {opacity: 0;}
  to {opacity: 1;}
}
/* === SmartBar FIX 2025.11.02 === */
#smartBar {
  position: fixed;
  right: 10px;
  bottom: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
}
#smartBar .sb-btn {
  background: #111;
  border: 1px solid #ff7b29;
  border-radius: 50%;
  width: 58px;
  height: 58px;
  color: #fff;
  font-size: 14px;
  text-align: center;
  line-height: 1.1;
  cursor: pointer;
  transition: 0.2s ease;
}
#smartBar .sb-btn.active {
  background: #ff7b29;
  color: #111;
}
#smartBar .sb-btn span {
  display: block;
  font-size: 22px;
}
@media (max-width: 768px) {
  #smartBar {
    flex-direction: row;
    justify-content: space-around;
    left: 0;
    right: 0;
    bottom: 0;
    background: #0d0d0d;
    border-top: 1px solid #222;
    height: 60px;
  }
  #smartBar .sb-btn {
    flex: 1;
    border: none;
    border-radius: 0;
    height: 100%;
    font-size: 12px;
  }
  #smartBar .sb-btn span {
    font-size: 18px;
  }
}

/* pannelli opzionali (se vuoi riutilizzarli) */
.sb-panel {
  display: none;
  position: fixed;
  right: 80px;
  bottom: 20px;
  background: #111;
  color: #fff;
  border: 1px solid #ff7b29;
  border-radius: 12px;
  padding: 12px;
  z-index: 9998;
  width: 250px;
  min-height: 100px;
}
.sb-panel.active {
  display: block;
}
/* === FIX Riquadro Topbar Desktop === */
#fixedTopbar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 10px;
  background: rgba(20, 22, 28, 0.9);
  padding: 10px;
  z-index: 9999;
  backdrop-filter: blur(6px);
}

#fixedTopbar .pill {
  font-size: 14px;
  padding: 6px 14px;
}

/* Compensa l'altezza del topbar */
main.main {
  margin-top: 60px;
}

/* === FIX Barra Mobile === */
.mbar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: rgba(20, 22, 28, 0.95);
  display: flex;
  justify-content: space-around;
  z-index: 9999;
  padding: 6px 0;
}

.mbar-btn {
  flex: 1;
  color: #fff;
  background: transparent;
  border: none;
  font-size: 15px;
  text-align: center;
}
/* === FIX RIQUADRO TOPBAR DESKTOP === */
#fixedTopbar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 10px;
  background: rgba(20, 22, 28, 0.9);
  padding: 10px;
  z-index: 9999;
  backdrop-filter: blur(6px);
}

#fixedTopbar .pill {
  font-size: 14px;
  padding: 6px 14px;
}

/* Compensa l'altezza della barra */
main.main {
  margin-top: 60px;
}
/* Nasconde la barra mobile e i pannelli da desktop */
@media (min-width: 768px) {
  .mbar,
  #chatPanel,
  #customizePanel,
  #actionsPanel {
    display: none !important;
  }
}
:root {
  --bg-dark: #0d0d0d;
  --fg-light: #eaeaea;
  --accent: #ff7b00;
  --system: #29c7ac;
  --danger: #ff4444;
}
body {
  background: var(--bg-dark);
  color: var(--fg-light);
}
.pill,
button.pill {
  background: var(--accent);
  color: #000;
}
.pill.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.muted {
  color: #9b9b9b;
}
/* =============================================
   MESSAGGIO CON MENU PULITO
   ============================================= */
.msg-tools {
  position: absolute;
  top: 8px;
  right: 8px;
  opacity: 0;
  transition: opacity 0.2s;
}

.msg:hover .msg-tools {
  opacity: 1;
}

.msg-menu {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
}

.msg-menu:hover {
  background: rgba(255, 255, 255, 0.2);
}

.msg-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--panel);
  border: 1px solid #26303a;
  border-radius: 8px;
  padding: 8px;
  display: none;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.msg-dropdown.show {
  display: flex;
}

.msg-dropdown button {
  padding: 8px 12px;
  text-align: left;
  border-radius: 4px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 0.85em;
  cursor: pointer;
}

.msg-dropdown button:hover {
  background: rgba(255, 255, 255, 0.1);
}
/* =============================================
   PRO CARD MIGLIORATA
   ============================================= */
.pro-card-enhanced {
  padding: 20px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(255, 123, 41, 0.1) 0%, rgba(41, 199, 172, 0.05) 100%);
  position: relative;
  overflow: hidden;
}

.pro-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--accent);
  color: #111;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.75em;
  font-weight: 800;
}

.pro-content h4 {
  margin-bottom: 12px;
  font-weight: 700;
  color: var(--accent);
}

.pro-features {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.pro-feature {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9em;
}

.pro-icon {
  font-size: 1.1em;
}

.pill.pro-cta {
  width: 100%;
  background: var(--accent);
  color: #111;
  font-weight: 700;
  padding: 10px 16px;
  margin-bottom: 8px;
}

.pro-cta-sub {
  text-align: center;
  display: block;
}

.pro-cta-sub a {
  color: var(--accent);
  font-weight: 600;
}
/* =============================================
   INFO PROGETTO
   ============================================= */
.project-info {
  padding: 16px;
  background: rgba(255, 123, 41, 0.05);
  border: 1px solid rgba(255, 123, 41, 0.2);
  border-radius: var(--radius);
  margin: 16px 0;
}

.project-info .side-title {
  margin-top: 0;
}

.project-links {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.project-links .pill {
  font-size: 0.8em;
  padding: 4px 8px;
  flex: 1;
  text-align: center;
}
