/* =========================================================================
   Cardinale Assistant — design system "deep craft"
   Tema chiaro (default) + scuro · accento blu · vetro, profondità, luce
   ========================================================================= */
:root {
  --bg: #eef1f7;
  --bg-2: #e6eaf3;
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --glass: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.6);
  --border: #e3e7ef;
  --border-strong: #d2d8e4;
  --text: #0e131c;
  --text-soft: #3b4555;
  --muted: #707a8a;
  --accent: #2563eb;
  --accent-2: #4f8bff;
  --accent-press: #1b4fd6;
  --accent-soft: #e7f0ff;
  --accent-glow: rgba(37, 99, 235, 0.30);
  --on-accent: #ffffff;
  --danger: #dc2626;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05), 0 2px 6px rgba(16, 24, 40, .05);
  --shadow-md: 0 10px 30px -8px rgba(16, 24, 40, .18);
  --shadow-lg: 0 24px 60px -16px rgba(16, 24, 40, .28);
  --aurora-1: rgba(79, 139, 255, 0.20);
  --aurora-2: rgba(37, 99, 235, 0.12);
  --aurora-3: rgba(168, 85, 247, 0.10);
}
:root[data-theme="dark"] {
  --bg: #080b11;
  --bg-2: #0c1019;
  --surface: #141a25;
  --surface-2: #1b2230;
  --glass: rgba(18, 23, 33, 0.66);
  --glass-border: rgba(255, 255, 255, 0.07);
  --border: #262e3d;
  --border-strong: #333d50;
  --text: #eef2f8;
  --text-soft: #c2cad6;
  --muted: #8b95a6;
  --accent: #5b93ff;
  --accent-2: #7aabff;
  --accent-press: #3f7bf0;
  --accent-soft: #16233e;
  --accent-glow: rgba(91, 147, 255, 0.40);
  --on-accent: #ffffff;
  --danger: #f0676b;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 12px 32px -10px rgba(0,0,0,.6);
  --shadow-lg: 0 28px 64px -18px rgba(0,0,0,.7);
  --aurora-1: rgba(91, 147, 255, 0.22);
  --aurora-2: rgba(37, 99, 235, 0.16);
  --aurora-3: rgba(124, 58, 237, 0.16);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  transition: background-color .4s ease, color .4s ease;
}
/* Sfondo vivo, appena percettibile */
body::before {
  content: "";
  position: fixed; inset: -20%;
  z-index: -1;
  background:
    radial-gradient(40% 38% at 18% 12%, var(--aurora-1), transparent 70%),
    radial-gradient(36% 34% at 85% 22%, var(--aurora-3), transparent 70%),
    radial-gradient(50% 44% at 65% 100%, var(--aurora-2), transparent 72%);
  filter: blur(20px);
  animation: drift 26s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes drift {
  0%   { transform: translate3d(0,0,0) scale(1); }
  100% { transform: translate3d(0,-3%,0) scale(1.08); }
}
@media (prefers-reduced-motion: reduce) { body::before { animation: none; } }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.logo {
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border-radius: 10px;
  background: linear-gradient(140deg, var(--accent-2), var(--accent-press));
  color: #fff; font-weight: 800; font-size: 15px;
  letter-spacing: 0;
  box-shadow: 0 4px 12px -2px var(--accent-glow), inset 0 1px 0 rgba(255,255,255,.4);
  flex-shrink: 0;
}

/* ---------- Login ---------- */
.login { height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box {
  background: var(--glass);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  backdrop-filter: blur(24px) saturate(1.4);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 30px;
  width: 380px; max-width: 100%;
  display: flex; flex-direction: column; gap: 18px;
  box-shadow: var(--shadow-lg);
  animation: rise .5s cubic-bezier(.22,.61,.36,1);
}
.login-brand { display: flex; align-items: center; gap: 13px; }
.login-brand .logo { width: 44px; height: 44px; font-size: 20px; border-radius: 13px; }
.login-title { font-weight: 700; font-size: 18px; letter-spacing: -.02em; }
.field { display: flex; flex-direction: column; gap: 7px; font-size: 13px; color: var(--muted); }
.field input {
  padding: 13px 15px; border-radius: 13px;
  border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-size: 16px;
  transition: border-color .18s, box-shadow .18s;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.btn-primary {
  padding: 13px; border: none; border-radius: 13px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent-press));
  color: var(--on-accent);
  font-size: 15px; font-weight: 600; cursor: pointer;
  box-shadow: 0 6px 18px -4px var(--accent-glow);
  transition: filter .18s, transform .08s, box-shadow .18s;
}
.btn-primary:hover { filter: brightness(1.06); box-shadow: 0 10px 26px -6px var(--accent-glow); }
.btn-primary:active { transform: translateY(1px); }
.error { color: var(--danger); font-size: 13px; min-height: 16px; text-align: center; }

/* ---------- App shell ---------- */
.app { height: 100dvh; display: flex; flex-direction: column; max-width: 900px; margin: 0 auto; position: relative; }
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  backdrop-filter: blur(20px) saturate(1.5);
  border-bottom: 1px solid var(--glass-border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -.02em; }
.brand-accent { color: var(--accent); }
.header-actions { display: flex; align-items: center; gap: 8px; }

/* Selettore azienda */
.company-switch { position: relative; margin: 0 auto 0 14px; }
.company-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid transparent; cursor: pointer;
  padding: 8px 12px; border-radius: 11px;
  font-size: 13.5px; font-weight: 600; letter-spacing: -.01em;
  max-width: 230px; transition: filter .15s, border-color .15s;
}
.company-btn:hover { border-color: var(--accent); }
.company-btn #companyName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.company-btn .chev { opacity: .8; flex-shrink: 0; }
.company-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30;
  min-width: 230px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 13px; box-shadow: var(--shadow-lg); padding: 6px;
  animation: rise .16s ease;
}
.company-menu .c-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 9px; cursor: pointer; font-size: 14px;
  transition: background .12s;
}
.company-menu .c-item:hover { background: var(--surface-2); }
.company-menu .c-item.active { color: var(--accent); font-weight: 600; }
.company-menu .c-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); flex-shrink: 0; }
.company-menu .c-item.active .c-dot { background: var(--accent); }
.company-menu .c-group { font-weight: 600; border-bottom: 1px solid var(--border); margin-bottom: 4px; padding-bottom: 12px; }
.company-menu .c-group .c-dot { background: linear-gradient(135deg, var(--accent-2), var(--accent-press)); }

.btn-ghost {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border-strong);
  color: var(--text); padding: 8px 13px; border-radius: 11px;
  font-size: 13px; font-weight: 500; cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background .16s, border-color .16s, transform .08s;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost:active { transform: translateY(1px); }

.icon-btn {
  display: grid; place-items: center;
  border: none; cursor: pointer; border-radius: 13px;
  width: 44px; height: 44px; flex-shrink: 0;
  transition: background .16s, transform .08s, filter .16s, box-shadow .16s;
}
.icon-btn:active { transform: scale(.92); }
.ghost-icon { width: 38px; height: 38px; background: var(--surface); border: 1px solid var(--border-strong); color: var(--text-soft); box-shadow: var(--shadow-sm); }
.ghost-icon:hover { color: var(--accent); border-color: var(--accent); }

.ico-moon { display: none; }
:root[data-theme="dark"] .ico-sun { display: none; }
:root[data-theme="dark"] .ico-moon { display: block; }

/* ---------- Messaggi ---------- */
.messages {
  flex: 1; overflow-y: auto;
  padding: 24px 18px 8px;
  display: flex; flex-direction: column; gap: 18px;
  scroll-behavior: smooth;
}

/* Welcome */
.welcome { margin: auto 0; text-align: center; padding: 16px; animation: rise .6s cubic-bezier(.22,.61,.36,1); }
.welcome-logo {
  width: 64px; height: 64px; margin: 0 auto 18px;
  display: grid; place-items: center; border-radius: 20px;
  background: linear-gradient(140deg, var(--accent-2), var(--accent-press));
  color: #fff; font-weight: 800; font-size: 30px;
  box-shadow: 0 14px 40px -8px var(--accent-glow), inset 0 1px 0 rgba(255,255,255,.4);
  animation: float 5s ease-in-out infinite;
}
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
@media (prefers-reduced-motion: reduce) { .welcome-logo { animation: none; } }
.welcome h2 { margin: 0 0 8px; font-size: 23px; letter-spacing: -.03em; }
.welcome p { margin: 0 auto 20px; max-width: 460px; color: var(--muted); }
.suggestions { display: flex; flex-wrap: wrap; gap: 11px; justify-content: center; max-width: 580px; margin: 0 auto; }
.chip {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-soft); padding: 11px 16px; border-radius: 14px;
  font-size: 13.5px; cursor: pointer; box-shadow: var(--shadow-sm);
  transition: border-color .18s, transform .12s, box-shadow .18s, color .18s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.chip:active { transform: translateY(0); }

/* Bolle */
.msg { display: flex; animation: msgIn .4s cubic-bezier(.22,.61,.36,1); }
@keyframes msgIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.msg.user { justify-content: flex-end; }
.msg .bubble { max-width: 84%; line-height: 1.6; word-wrap: break-word; }
.msg.user .bubble {
  background: linear-gradient(135deg, var(--accent-2), var(--accent-press));
  color: var(--on-accent);
  padding: 12px 16px; border-radius: 20px 20px 5px 20px;
  box-shadow: 0 8px 22px -8px var(--accent-glow);
  font-size: 15px;
}
.msg.assistant .bubble {
  background: var(--surface); border: 1px solid var(--border);
  padding: 16px 18px; border-radius: 20px 20px 20px 5px;
  box-shadow: var(--shadow-md); width: 100%;
}

/* Stato "pensa / agisce" */
.activity { display: flex; align-items: center; gap: 11px; color: var(--muted); font-size: 14px; }
.activity .spinner {
  width: 16px; height: 16px; flex-shrink: 0; border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, var(--accent-2), var(--accent-press));
  animation: breathe 1.5s ease-in-out infinite;
}
@keyframes breathe {
  0%,100% { transform: scale(.78); box-shadow: 0 0 0 0 var(--accent-glow); opacity: .8; }
  50%     { transform: scale(1.08); box-shadow: 0 0 14px 2px var(--accent-glow); opacity: 1; }
}
.activity .activity-text {
  background: linear-gradient(90deg, var(--muted) 20%, var(--text) 50%, var(--muted) 80%);
  background-size: 200% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 2.2s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  .activity .spinner { animation: none; }
  .activity .activity-text { animation: none; color: var(--text-soft); -webkit-text-fill-color: var(--text-soft); }
}

/* Markdown */
.answer:empty { display: none; }
.answer { line-height: 1.6; font-size: 15px; color: var(--text); }
.answer p { margin: 0 0 10px; }
.answer p:last-child { margin-bottom: 0; }
.answer .md-h { font-weight: 700; font-size: 16px; margin: 14px 0 8px; letter-spacing: -.02em; }
.answer ul, .answer ol { margin: 6px 0 11px; padding-left: 20px; }
.answer li { margin: 3px 0; }
.answer strong { color: var(--text); font-weight: 700; }
.answer code { background: var(--surface-2); padding: 2px 6px; border-radius: 7px; font-size: 13px; }
.answer table {
  border-collapse: separate; border-spacing: 0; margin: 12px 0; font-size: 13.5px;
  width: 100%; display: block; overflow-x: auto;
  border: 1px solid var(--border); border-radius: 12px;
}
.answer th, .answer td { border-bottom: 1px solid var(--border); padding: 9px 13px; text-align: left; white-space: nowrap; }
.answer th { background: var(--surface-2); font-weight: 600; position: sticky; top: 0; }
.answer tr:last-child td { border-bottom: none; }
.answer td:not(:first-child), .answer th:not(:first-child) { text-align: right; }
.answer tbody tr { transition: background .12s; }
.answer tbody tr:hover { background: var(--surface-2); }

/* Bottoni export tabella */
.tbl-tools { display: flex; gap: 6px; margin: 10px 0 -2px; }
.tbl-btn {
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text-soft);
  font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 9px; cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.tbl-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* Trace passi */
.steps { margin-top: 12px; }
.trace { font-size: 12.5px; color: var(--muted); }
.trace summary {
  cursor: pointer; user-select: none; display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 9px; background: var(--surface-2);
  border: 1px solid var(--border); list-style: none; transition: border-color .16s;
}
.trace summary:hover { border-color: var(--accent); }
.trace summary::-webkit-details-marker { display: none; }
.trace[open] summary { margin-bottom: 7px; }
.trace .step { padding: 3px 4px; }
.trace .step.err { color: var(--danger); }
.trace .step.esc { color: var(--accent); font-weight: 600; }
.err-text { color: var(--danger); }

/* Follow-up suggeriti */
.followups:not(:empty) { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.followups-label { width: 100%; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.chip-sm { padding: 7px 12px; font-size: 13px; border-radius: 11px; }
.chip-sm::before { content: "↳ "; color: var(--accent); }

/* File generati (download) */
.file-card {
  display: flex; align-items: center; gap: 12px;
  text-decoration: none; color: inherit;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 14px; padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, transform .1s, box-shadow .15s;
}
.file-card:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.file-card .file-ico {
  display: grid; place-items: center; flex-shrink: 0;
  width: 42px; height: 42px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent-press));
  color: #fff; font-weight: 800; font-size: 11px; letter-spacing: .02em;
}
.file-card .file-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.file-card .file-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card .file-sub { font-size: 12px; color: var(--muted); }
.file-card .file-dl { color: var(--accent); flex-shrink: 0; }

/* Grafici */
.artifacts { display: flex; flex-direction: column; gap: 14px; }
.artifacts:not(:empty) { margin-bottom: 14px; }
.chart-card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 16px; padding: 16px;
  box-shadow: var(--shadow-sm);
}
.chart-title { font-weight: 600; margin-bottom: 12px; font-size: 14px; letter-spacing: -.01em; }
.chart-canvas { position: relative; height: 290px; }
@media (max-width: 640px) { .chart-canvas { height: 240px; } }
.chart-hint { font-size: 11px; color: var(--muted); text-align: center; margin-top: 8px; opacity: .8; }

/* ---------- Composer ---------- */
.composer {
  padding: 14px 18px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 55%, transparent);
  position: sticky; bottom: 0;
}
.composer-bar {
  display: flex; align-items: flex-end; gap: 6px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  backdrop-filter: blur(20px) saturate(1.5);
  border: 1px solid var(--border-strong);
  border-radius: 26px;
  padding: 6px 7px;
  box-shadow: var(--shadow-md);
  transition: border-color .18s, box-shadow .18s;
}
.composer-bar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-md); }
.composer-bar textarea {
  flex: 1; resize: none; max-height: 140px;
  padding: 10px 8px; border: none; background: transparent;
  color: var(--text); font-size: 16px; font-family: inherit; line-height: 1.4;
}
.composer-bar textarea:focus { outline: none; }
.composer-bar textarea::placeholder { color: var(--muted); }
.mic { background: transparent; color: var(--muted); }
.mic:hover { background: var(--surface-2); color: var(--text); }
.mic.recording { background: var(--danger); color: #fff; animation: pulse 1.1s infinite; box-shadow: 0 0 0 6px rgba(220,38,38,.15); }
.send {
  background: linear-gradient(135deg, var(--accent-2), var(--accent-press)); color: var(--on-accent);
  box-shadow: 0 6px 16px -4px var(--accent-glow);
}
.send:hover { filter: brightness(1.08); box-shadow: 0 9px 22px -5px var(--accent-glow); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .7; } }

.status { text-align: center; font-size: 12px; color: var(--muted); min-height: 16px; margin-top: 8px; }

/* ---------- Drawer Storico ---------- */
.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-backdrop {
  position: absolute; inset: 0;
  background: rgba(8, 11, 17, .42);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.drawer-panel {
  position: absolute; top: 0; right: 0; height: 100%;
  width: 380px; max-width: 88vw;
  background: var(--glass);
  -webkit-backdrop-filter: blur(26px) saturate(1.5); backdrop-filter: blur(26px) saturate(1.5);
  border-left: 1px solid var(--glass-border);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  animation: slideIn .28s cubic-bezier(.22,.61,.36,1);
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: none; } }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; padding-top: calc(16px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
}
.drawer-title { font-weight: 700; font-size: 16px; letter-spacing: -.02em; }
.history-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.history-empty { color: var(--muted); text-align: center; padding: 40px 16px; font-size: 14px; }
.history-day { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: 12px 8px 4px; }
.history-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border);
  cursor: pointer; box-shadow: var(--shadow-sm);
  transition: border-color .15s, transform .1s;
}
.history-item:hover { border-color: var(--accent); transform: translateY(-1px); }
.history-item .h-main { flex: 1; min-width: 0; }
.history-item .h-title { font-size: 14px; font-weight: 600; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.history-item .h-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.history-del {
  flex-shrink: 0; border: none; background: transparent; color: var(--muted);
  cursor: pointer; padding: 4px; border-radius: 8px; line-height: 0;
  transition: color .15s, background .15s;
}
.history-del:hover { color: var(--danger); background: var(--surface-2); }
.readonly-banner {
  text-align: center; font-size: 12.5px; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 8px 12px; margin: 0 0 4px;
}

/* ---------- Memoria ---------- */
.mem-add { padding: 14px 14px 6px; border-bottom: 1px solid var(--border); }
.mem-add textarea {
  width: 100%; resize: vertical; min-height: 64px;
  border: 1px solid var(--border-strong); border-radius: 12px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 14px; padding: 10px 12px;
}
.mem-add textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.mem-add-row { display: flex; gap: 8px; margin-top: 8px; }
.mem-scope {
  flex: 1; min-width: 0; border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px; padding: 8px 10px;
}
.mem-save { padding: 8px 16px; border-radius: 10px; white-space: nowrap; }
.mem-hint { padding: 8px 14px 0; }

.mem-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.mem-item.off { opacity: 0.5; }
.mem-toggle { display: flex; align-items: center; padding-top: 2px; cursor: pointer; }
.mem-toggle input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.mem-body { flex: 1; min-width: 0; }
.mem-scope-chip {
  display: inline-block; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 7px; margin-bottom: 6px;
}
.mem-text { font-size: 13.5px; line-height: 1.45; cursor: text; white-space: pre-wrap; }
.mem-edit { width: 100%; min-height: 80px; border: 1px solid var(--accent); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-size: 13.5px; padding: 6px 8px; }

.msg-actions:not(:empty) { margin-top: 8px; }
.mem-saved-tag {
  display: inline-block; font-size: 12px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 9px; padding: 5px 11px;
}

/* ---------- Stampa / Esporta PDF ---------- */
@media print {
  @page { margin: 14mm; }
  html, body { height: auto; background: #fff; color: #000; }
  body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body::before { display: none !important; }
  header, .composer, .status, .drawer, .company-switch, .header-actions,
  .tbl-tools, .activity, .followups, .trace, .welcome { display: none !important; }
  .app { height: auto; max-width: 100%; display: block; }
  .messages { display: block; overflow: visible; padding: 0; height: auto; }
  .msg { display: block; break-inside: avoid; page-break-inside: avoid; margin-bottom: 12px; }
  .msg.user { text-align: right; }
  .msg .bubble {
    max-width: 100%; box-shadow: none !important;
    border: 1px solid #ddd; background: #fff !important; color: #000 !important;
    display: inline-block;
  }
  .msg.user .bubble { background: #f0f4ff !important; color: #000 !important; }
  .answer, .answer strong, .answer th, .answer td { color: #000 !important; }
  .answer table { border-color: #bbb; }
  .answer th { background: #eef !important; }
  .chart-card { border: 1px solid #ddd; background: #fff !important; break-inside: avoid; }
  .steps { display: none !important; }
}

/* ---------- Nascondi temporaneamente (rimuovere per riattivare) ---------- */
/* Microfono: in attesa di sistemare HTTPS/cookie. PDF: in attesa della generazione file lato agente. */
#micBtn, #pdfBtn { display: none !important; }

/* ---------- Dashboard admin ---------- */
.drawer-wide { width: 560px; max-width: 94vw; }
.admin-tabs { display: flex; gap: 6px; padding: 10px 14px 0; border-bottom: 1px solid var(--border); }
.admin-tab {
  background: transparent; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); font: inherit; font-size: 14px; font-weight: 600; padding: 8px 12px; cursor: pointer;
}
.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.admin-body { flex: 1; overflow-y: auto; padding: 14px; }
.period-row { display: flex; gap: 6px; align-items: center; margin-bottom: 12px; }
.period-btn { background: var(--surface); border: 1px solid var(--border-strong); color: var(--text-soft); border-radius: 9px; font-size: 12px; font-weight: 600; padding: 5px 11px; cursor: pointer; }
.period-btn.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.price-warn { font-size: 11.5px; color: #b45309; margin-left: auto; }
.kpi-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px; text-align: center; }
.kpi-val { font-size: 19px; font-weight: 700; letter-spacing: -.02em; }
.kpi-lbl { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.admin-sec-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 16px 0 8px; }
.admin-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td { padding: 8px 11px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.admin-table th { background: var(--surface-2); font-weight: 600; font-size: 11.5px; color: var(--muted); }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table td:nth-child(n+2), .admin-table th:nth-child(n+2) { text-align: right; }
.model-split { display: flex; gap: 10px; flex-wrap: wrap; }
.model-pill { flex: 1; min-width: 180px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.model-pill.adv { border-color: var(--accent); }
.user-add { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 14px; }
.user-add-row { display: flex; gap: 8px; margin-bottom: 8px; }
.user-add-row:last-of-type { margin-bottom: 0; }
.user-add input, .user-add select { flex: 1; min-width: 0; border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface); color: var(--text); font: inherit; font-size: 13px; padding: 8px 10px; }
.admin-table td { vertical-align: middle; }
.user-actions { display: flex; gap: 5px; justify-content: flex-end; }
.mini-btn { background: var(--surface); border: 1px solid var(--border-strong); color: var(--text-soft); border-radius: 8px; font-size: 11.5px; font-weight: 600; padding: 4px 8px; cursor: pointer; white-space: nowrap; }
.mini-btn:hover { border-color: var(--accent); color: var(--accent); }
.mini-btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.role-chip { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 7px; text-transform: uppercase; letter-spacing: .03em; }
.role-chip.admin { color: var(--accent); background: var(--accent-soft); }
.role-chip.user { color: var(--muted); background: var(--surface-2); }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .brand-name { display: none; }
  .kpi-grid { grid-template-columns: 1fr; }
  .user-add-row { flex-direction: column; }
  .company-switch { margin-left: 10px; }
  .company-btn { max-width: 150px; padding: 7px 10px; }
  header { padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .header-actions { gap: 6px; }
  .messages { padding: 18px 13px 6px; gap: 15px; }
  .msg .bubble { max-width: 90%; }
  .composer { padding: 11px 13px; padding-bottom: calc(9px + env(safe-area-inset-bottom)); }
  .welcome h2 { font-size: 21px; }
}
