/* ============================================================================
 * Tagghio — tema CHIARO + layout CRM (sidebar sinistra, drawer destro).
 * Palette dal logo: accent arancio/ambra in gradiente, viola scuro per i testi.
 * ========================================================================== */
:root {
  --bg: #f6f4f8;
  --panel: #ffffff;
  --panel-2: #faf8fc;
  --border: #e7e1ee;
  --text: #3c2744;
  --text-soft: #6b5d73;
  --muted: #9b8fa5;
  --accent: #ef8218;
  --accent-2: #f8b233;
  --accent-grad: linear-gradient(135deg, #ef8218 0%, #f19120 50%, #f8b233 100%);
  --ok: #1f9d55;
  --warn: #d9822b;
  --danger: #d64545;
  --shadow: 0 1px 2px rgba(60,39,68,.06), 0 6px 20px rgba(60,39,68,.06);
  --radius: 12px;
  --sidebar-w: 244px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---- App shell ------------------------------------------------------------ */
.app-shell { display: flex; min-height: 100vh; }

/* ---- Sidebar CRM ---------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 30;
}
.sidebar .brand { padding: 18px 18px 12px; }
.sidebar .brand img { height: 30px; }
.nav { padding: 8px; flex: 1; overflow-y: auto; }
.nav .group-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 14px 12px 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 9px;
  color: var(--text-soft); font-weight: 500; margin-bottom: 2px; transition: .12s;
}
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: rgba(239,130,24,.12); color: var(--accent); }
.nav a .ico { width: 18px; text-align: center; font-size: 16px; }
.nav a .badge { margin-left: auto; font-size: 11px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; }
.sidebar .foot { border-top: 1px solid var(--border); padding: 12px; font-size: 13px; color: var(--text-soft); }
.sidebar .foot .email { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 8px; }

/* ---- Main ----------------------------------------------------------------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar .sub { color: var(--muted); font-size: 13px; }
.topbar .spacer { flex: 1; }
.burger { display: none; border: 1px solid var(--border); background: var(--panel); border-radius: 9px; padding: 7px 11px; font-size: 16px; }
.wrap { padding: 20px; max-width: 1280px; width: 100%; margin: 0 auto; }
.topstats { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.topstats .hpill { background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; font-size: 12px; color: var(--text-soft); white-space: nowrap; }
.topstats .hpill b { color: var(--accent); font-weight: 700; }
.topstats .hpill:nth-child(2) b { color: var(--ok); }
@media (max-width: 980px) { .topstats { display: none; } }

.btn { border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 8px 14px; border-radius: 9px; transition: .15s; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-accent { border: none; color: #fff; background: var(--accent-grad); box-shadow: 0 2px 8px rgba(239,130,24,.35); }
.btn-accent:hover { filter: brightness(1.04); color: #fff; }

/* ---- Toolbar / filtri ----------------------------------------------------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); margin-bottom: 16px; }
.search { flex: 1; min-width: 220px; }
.search input, select, .input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2); color: var(--text); font: inherit; }
select { width: auto; min-width: 150px; }
input:focus, select:focus { outline: 2px solid var(--accent-2); border-color: var(--accent); }
label.chk { display: inline-flex; align-items: center; gap: 6px; color: var(--text-soft); font-size: 14px; }

/* ---- Multi-select (filtri multipli) --------------------------------------- */
.ms { position: relative; }
.ms > summary { list-style: none; cursor: pointer; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2); color: var(--text); white-space: nowrap; user-select: none; }
.ms > summary::-webkit-details-marker { display: none; }
.ms[open] > summary { border-color: var(--accent); color: var(--accent); }
.ms-panel { position: absolute; top: calc(100% + 4px); left: 0; z-index: 25; min-width: 250px; max-height: 320px; overflow: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 8px; }
.ms-panel label { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px; font-size: 14px; cursor: pointer; }
.ms-panel label:hover { background: var(--panel-2); }
.ms-panel .cnt { margin-left: auto; color: var(--muted); font-size: 12px; }
.ms-panel .ms-empty { color: var(--muted); padding: 8px; }
.ms-tools { display: flex; gap: 6px; margin-bottom: 8px; }
.ms-search { flex: 1; padding: 6px 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--panel-2); font: inherit; }
.ms-tools button { padding: 6px 8px; font-size: 12px; }
.ms-list { max-height: 240px; overflow: auto; }
.ms-list label.off .cnt { color: var(--danger); opacity: .7; }

/* barra azioni selezione multipla */
.bulkbar { display: flex; align-items: center; gap: 12px; background: rgba(239,130,24,.10); border: 1px solid var(--accent-2); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; }
.bulkbar #bulkN { font-weight: 600; }

/* ---- Crea offerta --------------------------------------------------------- */
.offer-input { width: 72px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--panel-2); font: inherit; text-align: right; }
.totbar { display: flex; flex-wrap: wrap; gap: 22px; align-items: center; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 18px; margin-top: 16px; }
.totbar .t { font-size: 13px; color: var(--text-soft); } .totbar .t b { display: block; font-size: 18px; color: var(--text); margin-top: 2px; }
.totbar .grow { flex: 1; }
.rm { padding: 4px 9px; color: var(--danger); }
.of-head { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
.fld { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-soft); }
.fld .input, .fld .offer-input { width: auto; }
.fld .offer-input { width: 110px; text-align: left; }
.comp { font-size: 13px; line-height: 1.35; }
.comp-best { color: var(--ok); font-weight: 600; }
.comp-2 { color: var(--text-soft); }
.gap-neg { color: var(--danger); }
/* candidati simili (Prodotti simili) */
.cands { display: flex; gap: 6px; flex-wrap: wrap; }
.cand { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; width: 88px; padding: 5px; border: 1px solid var(--border); border-radius: 9px; cursor: pointer; font-size: 11px; text-align: center; transition: .12s; }
.cand:hover { border-color: var(--accent); }
.cand.on { border-color: var(--accent); background: rgba(239,130,24,.08); box-shadow: 0 0 0 1px var(--accent) inset; }
.cand .thumb { width: 42px; height: 42px; }
.cand .cn { color: var(--text-soft); line-height: 1.15; height: 26px; overflow: hidden; }
.cand b { color: var(--accent); }
.ai-chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 10px; }
.ai-chips .chip { border: none; background: var(--accent-grad); color: #fff; font-weight: 600; border-radius: 999px; padding: 7px 13px; font-size: 13px; box-shadow: 0 2px 8px rgba(239,130,24,.30); }
.ai-chips .chip:hover { filter: brightness(1.05); color: #fff; }
/* Tagghio Intelligence — chat */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 150px); min-height: 420px; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 8px 2px 16px; }
.chat-empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--muted); text-align: center; }
.chat-empty .spark { font-size: 36px; color: var(--accent); animation: floaty 3s ease-in-out infinite; }
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.bubble { animation: fadeup .25s ease; }
@keyframes fadeup { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.bubble.user { margin: 12px 0 12px auto; max-width: 75%; background: var(--accent-grad); color: #fff; border-radius: 14px 14px 4px 14px; padding: 10px 15px; width: fit-content; }
.bubble.ai { margin: 12px auto 12px 0; max-width: 980px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px 14px 14px 4px; padding: 14px 16px; box-shadow: var(--shadow); }
.bubble.ai .ai-says { font-weight: 600; line-height: 1.4; }
.dots i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin: 0 2px; animation: blink 1.2s infinite both; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .2; } 40% { opacity: 1; } }
.thinking .status { color: var(--text-soft); margin-left: 6px; }
.chat-input { border-top: 1px solid var(--border); padding: 12px 2px 2px; }
.chat-row { display: flex; gap: 8px; align-items: center; }
.chat-send { width: 42px; height: 42px; flex: 0 0 42px; border: none; border-radius: 50%; background: var(--accent-grad); color: #fff; font-size: 19px; box-shadow: 0 2px 8px rgba(239,130,24,.35); }
.chat-send:hover { filter: brightness(1.05); }
.ai-bulk { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.ai-bulk .n { font-weight: 600; }
/* intestazioni ordinabili */
th.srt { cursor: pointer; user-select: none; }
th.srt:hover { color: var(--accent); }
th.srt .ar { color: var(--accent); font-size: 10px; margin-left: 2px; }
/* box Prezzo Furbo nel drawer */
.furbo-box { border: 1px solid var(--border); border-radius: 10px; padding: 6px 14px; margin-top: 12px; background: var(--panel-2); }
.fb-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.fb-row:last-child { border-bottom: 0; }
.fb-furbo { background: rgba(239,130,24,.07); margin: 0 -14px; padding: 8px 14px; }
.fb-furbo b { color: var(--accent); font-size: 16px; }
.b2b { color: var(--accent); }

/* modale generica (scelta copie PDF) */
.modal-bg { position: fixed; inset: 0; background: rgba(60,39,68,.4); z-index: 60; display: flex; align-items: center; justify-content: center; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 24px; width: 420px; max-width: 92vw; text-align: center; }
.modal h3 { margin: 0 0 4px; }
.modal-btns { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.modal-btns .btn-accent { padding: 10px 16px; }

/* avviso EAN incoerente ("conflitto") */
.warn-banner { background: rgba(214,69,69,.10); border: 1px solid rgba(214,69,69,.3); color: var(--danger); border-radius: 9px; padding: 9px 12px; font-size: 13px; margin-bottom: 12px; }

/* ---- Tabella -------------------------------------------------------------- */
.grid { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: 12px; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--border); background: var(--panel-2); white-space: nowrap; }
tbody td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel-2); }
.thumb { width: 44px; height: 44px; object-fit: contain; border-radius: 8px; background: #fff; border: 1px solid var(--border); }
.thumb.ph { display: inline-flex; align-items: center; justify-content: center; color: var(--muted); font-size: 18px; }
.name { font-weight: 600; max-width: 420px; }
.name small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.price { font-weight: 700; white-space: nowrap; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: rgba(239,130,24,.12); color: var(--accent); }
.pill.gap { background: rgba(31,157,85,.12); color: var(--ok); }
.pill.cat { background: var(--panel-2); color: var(--text-soft); border: 1px solid var(--border); }
.muted { color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px; }
.pager .info { color: var(--text-soft); font-size: 14px; }
.empty { color: var(--muted); padding: 48px; text-align: center; }

/* ---- Card / sezioni generiche --------------------------------------------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card h2 { margin: 0 0 4px; font-size: 17px; }
.card .hint { color: var(--text-soft); font-size: 14px; margin: 0 0 14px; }
.status-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.status-row:last-child { border-bottom: 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 9px; }
.dot.ok { background: var(--ok); } .dot.ko { background: var(--danger); }
.status-row .f { font-weight: 600; min-width: 130px; }
.status-row .err { color: var(--danger); font-size: 13px; }

/* ---- Stati / login -------------------------------------------------------- */
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; gap: 16px; text-align: center; }
.loading img { width: 120px; }
.login-card { width: 360px; max-width: 92vw; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 28px; text-align: center; }
.login-card img.logo { height: 40px; margin-bottom: 18px; }
.login-card input { margin-bottom: 12px; }
.login-card .btn-accent { width: 100%; padding: 11px; }
.error { color: var(--danger); font-size: 14px; min-height: 18px; margin-top: 8px; }

/* ---- Drawer dettaglio ----------------------------------------------------- */
.drawer-bg { position: fixed; inset: 0; background: rgba(60,39,68,.35); z-index: 40; display: none; }
.drawer-bg.open { display: block; }
.drawer { position: fixed; top: 0; right: 0; height: 100%; width: 540px; max-width: 96vw; background: var(--panel); border-left: 1px solid var(--border); box-shadow: -10px 0 40px rgba(60,39,68,.18); z-index: 41; transform: translateX(100%); transition: transform .22s ease; overflow-y: auto; }
.drawer.open { transform: translateX(0); }
.drawer header { display: flex; gap: 12px; align-items: flex-start; padding: 20px; border-bottom: 1px solid var(--border); }
.drawer header img { width: 72px; height: 72px; object-fit: contain; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.drawer h3 { margin: 0 0 4px; font-size: 17px; }
.drawer .body { padding: 16px 20px 28px; }
.offer-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.offer-row .f { font-weight: 600; }
.best { color: var(--ok); font-weight: 600; }
.x { margin-left: auto; background: none; border: none; font-size: 24px; color: var(--muted); line-height: 1; }

/* ---- Sezioni comprimibili nel drawer -------------------------------------- */
.collap { border: 1px solid var(--border); border-radius: 10px; margin-top: 14px; overflow: hidden; }
.collap > summary { list-style: none; cursor: pointer; padding: 12px 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; background: var(--panel-2); }
.collap > summary::-webkit-details-marker { display: none; }
.collap > summary .chev { margin-left: auto; transition: transform .18s; color: var(--muted); }
.collap[open] > summary .chev { transform: rotate(90deg); }
.collap .collap-body { padding: 14px; }
.sec-title { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin: 18px 0 8px; }
.sim-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sim-card { border: 1px solid var(--border); border-radius: 10px; padding: 10px; font-size: 13px; cursor: pointer; }
.sim-card:hover { border-color: var(--accent); }
.sim-card .price { font-size: 14px; }

/* ---- Mini chart storico --------------------------------------------------- */
.chart { width: 100%; height: 120px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .area { fill: rgba(239,130,24,.10); stroke: none; }
.chart .dot { fill: var(--accent); }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart-meta { display: flex; gap: 18px; margin-top: 8px; font-size: 13px; color: var(--text-soft); }
.chart-meta b { color: var(--text); }

/* ---- Vendibilità ---------------------------------------------------------- */
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px; font-size: 14px; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 600; text-align: right; }
.src-badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--border); color: var(--text-soft); margin-bottom: 8px; }

/* ---- File upload (impostazioni) ------------------------------------------- */
.drop { border: 1.5px dashed var(--border); border-radius: 10px; padding: 18px; text-align: center; color: var(--text-soft); }
.drop input { display: none; }
.up-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }

/* ---- Responsive: sidebar off-canvas + burger ------------------------------ */
.scrim { display: none; position: fixed; inset: 0; background: rgba(60,39,68,.35); z-index: 29; }
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .22s ease; box-shadow: 8px 0 40px rgba(60,39,68,.18); }
  .app-shell.nav-open .sidebar { transform: translateX(0); }
  .app-shell.nav-open .scrim { display: block; }
  .burger { display: inline-block; }
  .sim-grid { grid-template-columns: 1fr; }
}

/* ============================================================================
 * UI/UX UPGRADE (taste-skill) — font, controlli uniformi, densità compatta,
 * stati, mobile, leggibilità dati. Non cambia la struttura/funzioni: solo stile.
 * ========================================================================== */
:root {
  --ctl-h: 34px;
  --radius: 10px;
  --sidebar-w: 220px;
  --shadow: 0 1px 2px rgba(60,39,68,.05), 0 6px 18px rgba(60,39,68,.06);
}
html { scroll-behavior: smooth; }
/* Schermo bloccato: si scorre solo in verticale, mai in orizzontale ------------ */
html, body { max-width: 100%; overflow-x: hidden; overscroll-behavior-x: none; }
.app-shell, .main, .wrap, .topbar, #content { max-width: 100%; min-width: 0; overflow-x: clip; }
/* Niente zoom/ritardo sul tap dei controlli, niente doppio-tap che ingrandisce */
button, a, .btn, .btn-accent, .chip, .nav a, .ms > summary, summary, input, select, label.chk, .cand, .sim-card, tbody tr { touch-action: manipulation; }
img, svg, table, video, canvas { max-width: 100%; }
body { font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif; font-size: 14px; }
h1, h2, h3, .name, .price, .b2b, .tot, .totbar b { letter-spacing: -.01em; }
/* numeri tabellari per dati allineati e leggibili */
.price, .b2b, .pill, .hpill b, td, th, .totbar b, .fb-row b, .kv .v, .pager, .info, .offer-input { font-variant-numeric: tabular-nums; }

/* ---- Controlli uniformi (bottoni, select, input, filtri, chip) ---- */
.btn, .btn-accent, .ms > summary {
  height: var(--ctl-h); padding: 0 12px; border-radius: var(--radius);
  font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px;
  line-height: 1; white-space: nowrap; transition: background .15s, border-color .15s, transform .08s, color .15s;
}
select { height: var(--ctl-h); padding: 0 28px 0 12px; border-radius: var(--radius); font-size: 13px; font-weight: 500; }
.search input, .input { height: var(--ctl-h); padding: 0 12px; border-radius: var(--radius); font-size: 13px; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:active, .btn-accent:active, .chip:active, .nav a:active { transform: translateY(1px); }
.btn:disabled, .btn-accent:disabled { opacity: .5; cursor: default; transform: none; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }
input:focus, select:focus { outline: 2px solid var(--accent-2); outline-offset: 0; border-color: var(--accent); }
.chip { transition: .15s; }
/* bottoni piccoli contestuali restano compatti */
.rm, .x { height: auto; }
.rm { padding: 4px 9px; }

/* ---- Toolbar / filtri più compatti e ordinati ---- */
.toolbar { padding: 9px; gap: 8px; border-radius: var(--radius); }
.ms-panel { border-radius: var(--radius); }

/* ---- Tabelle: compatte e leggibili. NIENTE scroll orizzontale su desktop ---- */
.grid { overflow-x: visible; }
.drop { margin-top: 8px; }
/* tag Amazon (vendibilità) */
.azpill { display: inline-flex; align-items: center; justify-content: center; height: 18px; padding: 0 4px; border-radius: 5px; background: #fff; border: 1px solid var(--border); box-shadow: var(--shadow); margin-left: 6px; vertical-align: middle; }
.azpill svg { display: block; }
.azline { display: flex; align-items: center; gap: 5px; margin-top: 4px; font-size: 11px; color: var(--text-soft); }
.azline .azpill { margin-left: 0; }
thead th { padding: 9px 12px; font-size: 11px; }
tbody td { padding: 8px 12px; }
tbody tr { transition: background .1s; }
.thumb { width: 38px; height: 38px; border-radius: 7px; }
.name { font-weight: 600; }
.name small { font-size: 11px; margin-top: 1px; }
.pill { border-radius: 7px; }
.pager { padding: 12px; }

/* ---- Sidebar più stretta e densa ---- */
.sidebar .brand { padding: 16px 16px 8px; }
.sidebar .brand img { height: 26px; }
.nav a { padding: 8px 11px; font-size: 14px; border-radius: 9px; }
.nav a .ico { font-size: 15px; }

/* ---- Card / sezioni ---- */
.card { padding: 16px 18px; border-radius: var(--radius); }
.card h2 { font-size: 16px; }

/* ---- Drawer ---- */
.drawer header { padding: 18px; }

/* ---- Mobile: leggibilità e fruibilità ---- */
@media (max-width: 860px) {
  body { font-size: 13px; }
  .wrap { padding: 12px; }
  .topbar { padding: 10px 14px; }
  .topbar h1 { font-size: 16px; }
  .toolbar { padding: 8px; gap: 6px; }
  .toolbar .search { min-width: 100%; order: -1; }
  .drawer { width: 100%; max-width: 100%; }
  .card { padding: 14px; }
  .totbar { gap: 14px; padding: 12px 14px; }
  /* i filtri multipli a tutta larghezza, mai oltre il bordo schermo */
  .toolbar > .ms, .toolbar > select, .toolbar .btn { flex: 1 1 auto; }
  .ms-panel { min-width: 0; width: min(88vw, 340px); }
}

/* ============================================================================
 * MOBILE — tabelle → schede impilate. Niente scroll orizzontale: ogni riga
 * diventa una card e ogni cella mostra l'etichetta della colonna (data-th).
 * ========================================================================== */
@media (max-width: 860px) {
  .grid { overflow: hidden; }
  .grid table, .grid thead, .grid tbody, .grid tr, .grid td { display: block; width: 100%; }
  .grid thead { display: none; }                 /* l'ordinamento da header è desktop-only */
  .grid tbody tr {
    display: flex; flex-wrap: wrap; align-items: flex-start; gap: 2px 12px;
    padding: 12px 14px; border-bottom: 1px solid var(--border);
  }
  .grid tbody tr:last-child { border-bottom: 0; }
  /* riga generica: etichetta a sx, valore a dx, a tutta larghezza */
  .grid tbody td {
    flex: 1 1 100%; display: flex; align-items: baseline; justify-content: space-between;
    gap: 14px; padding: 3px 0; border: 0; text-align: right; min-width: 0; word-break: break-word;
  }
  .grid tbody td::before {
    content: attr(data-th); flex: 0 0 40%; text-align: left; color: var(--muted);
    font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
    white-space: nowrap; align-self: center;
  }
  /* prima riga della card: miniatura + nome prodotto affiancati */
  .grid tbody td.nolabel { flex: 1 1 100%; display: block; text-align: left; padding: 3px 0; }
  .grid tbody td.nolabel::before { content: none; }
  .grid tbody td.nolabel:has(input[type="checkbox"]) { display: none; }      /* selezione multipla nascosta su mobile */
  .grid tbody td.nolabel:has(.thumb), .grid tbody td.nolabel:has(.pimg) { flex: 0 0 auto; padding: 0 0 2px; }
  .grid tbody td.name { flex: 1 1 60%; display: block; text-align: left; font-size: 14px; padding: 0 0 2px; }
  .grid tbody td.name::before { content: none; }
  .grid tbody td.name { max-width: none; }
  .grid tbody td.name small { font-size: 11px; }
  /* celle "blocco" (competitor, candidati simili, bottone rimuovi): a capo intero */
  .grid tbody td.comp, .grid tbody td.cands { flex: 1 1 100%; display: block; text-align: left; }
  .grid tbody td.comp::before, .grid tbody td.cands::before { display: block; margin-bottom: 4px; flex: none; }
  .grid tbody td.cands .cands { justify-content: flex-start; }
  .grid tbody td .offer-input { width: 96px; max-width: 50%; text-align: right; }
  /* niente celle vuote che lasciano una riga "etichetta —" a vuoto */
  .grid tbody td:empty { display: none; }
  thead th, tbody td { padding: 8px 9px; }
  /* tabella risultati AI: la bolla non sfora */
  .bubble.ai { max-width: 100%; }
  .bubble.user { max-width: 88%; }
}

/* ============================================================================
 * SOURCING KEEPA — tab, recap copertura, badge concorrenza/Amazon, score,
 * trend BuyBox, freschezza, pannello nel drawer. Riusa i token esistenti.
 * ========================================================================== */
.tabs { display: inline-flex; gap: 4px; background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 3px; margin-bottom: 14px; }
.tabs button { border: 0; background: transparent; color: var(--text-soft); font: inherit; font-weight: 600; padding: 6px 16px; border-radius: 7px; cursor: pointer; }
.tabs button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.kstat { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; color: var(--text-soft); font-size: 13px; margin: -4px 0 12px; }
.kstat b { color: var(--text); font-variant-numeric: tabular-nums; }
.kstat .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--border); }
.kbadge { display: inline-block; padding: 1px 8px; border-radius: 7px; font-size: 11px; font-weight: 700; }
.kbadge.amz { background: rgba(214,69,69,.12); color: var(--danger); }
.kbadge.free { background: rgba(31,157,85,.12); color: var(--ok); }
.kscore { font-weight: 700; font-variant-numeric: tabular-nums; }
.kscore.hi { color: var(--ok); }
.kscore.lo { color: var(--danger); }
.kscore.mid { color: var(--text-soft); }
.ktrend { font-size: 11px; color: var(--muted); }
.ktrend.max { color: var(--ok); }
.ktrend.min { color: var(--warn); }
.kfresh { font-size: 11px; color: var(--muted); white-space: nowrap; }
.koff small { color: var(--muted); }
/* pannello Keepa nel drawer */
.kpanel { margin: 4px 0 2px; }
.kpanel .kgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 14px; }
.kpanel .kv { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.kpanel .kv span { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.kpanel .kv b { font-size: 15px; font-variant-numeric: tabular-nums; }
.kpanel .kv b.pos { color: var(--ok); }
.kpanel .kv b.neg { color: var(--danger); }
.kpanel .kmeta { margin-top: 8px; font-size: 12px; color: var(--text-soft); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
/* caricamento Keepa: dots + skeleton shimmer (mai statico) */
.kload { display: flex; align-items: center; gap: 8px; color: var(--text-soft); font-size: 13px; margin-bottom: 10px; }
.kskel { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 14px; }
.kskel i { display: block; height: 30px; border-radius: 8px; background: linear-gradient(90deg, var(--panel-2) 25%, var(--border) 50%, var(--panel-2) 75%); background-size: 300% 100%; animation: kshimmer 1.15s ease-in-out infinite; }
@keyframes kshimmer { 0% { background-position: 150% 0; } 100% { background-position: -150% 0; } }
#dAzPill .azpill { display: inline-block; margin-top: 6px; }
@media (prefers-reduced-motion: reduce) { .kskel i { animation: none; } }

/* ===== CRM Anagrafiche + Offerte via mail ================================= */
/* Modal grande (form anagrafica): variante del .modal centrato esistente */
.modal.modal-lg { width: 760px; max-width: 94vw; text-align: left; padding: 0; max-height: 88vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
.modal-head .x { background: none; border: none; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.modal-head .x:hover { color: var(--text); }
.modal-body { padding: 18px 20px; overflow: auto; }
.modal-foot { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-actions { display: flex; gap: 10px; margin-left: auto; }
.modal-foot .error { flex-basis: 100%; text-align: right; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-grid .fld .input { width: 100%; }
.fld textarea.input { height: auto; min-height: 64px; resize: vertical; line-height: 1.45; padding: 8px 12px; }
.chk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 12px; margin-top: 4px; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); cursor: pointer; }
.chk input { width: auto; height: auto; }
.btn.danger { border-color: rgba(214,69,69,.5); color: var(--danger); }
.btn.danger:hover { background: rgba(214,69,69,.08); border-color: var(--danger); }
/* Badge di stato (relazione CRM + stato offerta) */
.stato { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.st-attivo, .st-approvata { background: rgba(31,157,85,.14); color: var(--ok); }
.st-lead, .st-da_approvare { background: rgba(239,130,24,.14); color: var(--accent); }
.st-sospeso { background: rgba(217,130,43,.16); color: var(--warn); }
.st-cessato, .st-scartata { background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
/* Rating a stelle */
.star { color: var(--border); font-size: 13px; }
.star.on { color: var(--accent-2); }
/* Tag "auto" (anagrafica creata dall'ingest) */
.tag-auto { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border: 1px solid var(--border); border-radius: 5px; padding: 0 4px; vertical-align: middle; }
.mono { font-variant-numeric: tabular-nums; }
/* Gap (offerta vs nostro costo) */
.gap-good { color: var(--ok); font-weight: 700; }
.gap-bad { color: var(--danger); font-weight: 600; }
tr.row-good td { background: rgba(31,157,85,.05); }
/* Azioni offerta + segmented inserire/scarta */
.om-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg-btn { border: none; background: var(--panel); color: var(--text-soft); padding: 5px 11px; font: inherit; font-size: 12px; cursor: pointer; border-left: 1px solid var(--border); transition: .12s; }
.seg-btn:first-child { border-left: none; }
.seg-btn:hover:not(:disabled) { color: var(--text); }
.seg-btn.ins.on { background: rgba(31,157,85,.16); color: var(--ok); font-weight: 700; }
.seg-btn.sc.on { background: var(--panel-2); color: var(--text); font-weight: 700; }
.seg-btn:disabled { opacity: .4; cursor: not-allowed; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } }
