/* Revolution Lab Agenti */
:root {
  --red: #e30613;
  --red-dark: #b8050f;
  --red-soft: #fdecee;
  --black: #0b0b0b;
  --ink: #18181b;
  --muted: #71717a;
  --line: #e4e4e7;
  --bg: #f4f4f5;
  --card: #ffffff;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .2em 0 .6em; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0 0 .8em; }
h3 { font-size: 1rem; margin: 1.2em 0 .6em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.r { text-align: right; }
.hidden { display: none !important; }
code { background: #eee; padding: 1px 5px; border-radius: 4px; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  background: var(--black); color: #fff;
  padding: 10px 20px; padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 3px solid var(--red);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 300; letter-spacing: .06em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand img { height: 34px; width: auto; }
.brand b { font-weight: 700; }
.mainnav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; align-items: center; }
.mainnav a { color: #d4d4d8; padding: 8px 12px; border-radius: 8px; font-size: .95rem; }
.mainnav a:hover { color: #fff; background: #222; text-decoration: none; }
.mainnav a.active { color: #fff; background: var(--red); }
.mainnav .logout { color: #a1a1aa; }
.dot { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--red); color: #fff; font-size: .75rem; text-align: center; font-weight: 700; }
.mainnav a.active .dot { background: #fff; color: var(--red); }
.menu-btn { display: none; margin-left: auto; background: none; border: 1px solid #333; color: #fff; font-size: 1.3rem; border-radius: 8px; padding: 4px 12px; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 24px 20px 120px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 0 0 30px; }

/* ---------- Card & layout ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.card.narrow { max-width: 560px; }
.cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }
.cols > .card { margin-bottom: 0; }
.cols + .cols { margin-top: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }
.span2 { grid-column: span 2; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Form ---------- */
label { display: block; font-size: .85rem; font-weight: 600; color: #3f3f46; margin-bottom: 14px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 5px;
  font: inherit; font-size: 16px; color: var(--ink);
  padding: 11px 12px; border: 1px solid #d4d4d8; border-radius: 9px; background: #fff;
  min-height: 46px;
}
textarea { resize: vertical; min-height: 0; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(227,6,19,.15); }
input[type=file] { padding: 9px; background: #fafafa; font-size: .9rem; }
input:disabled { background: #f4f4f5; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 10px; font-weight: 500; margin-top: 26px; }
label.check input { width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--red); }
input.num { max-width: 110px; min-height: 40px; padding: 7px 9px; margin: 0; }
input.num.pct { max-width: 70px; font-weight: 700; text-align: center; }

/* ---------- Bottoni ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer;
  padding: 10px 18px; min-height: 44px; border-radius: 9px;
  border: 1px solid #d4d4d8; background: #fff; color: var(--ink);
}
.btn:hover { text-decoration: none; border-color: #a1a1aa; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: #f4f4f5; }
.btn.danger { color: var(--red); }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: .85rem; }
.btn.big { padding: 14px 26px; font-size: 1.05rem; }
.btn.block { display: flex; width: 100%; }
.btn.dashed { border-style: dashed; border-color: #a1a1aa; background: #fafafa; }
.btn.dashed:hover { border-color: var(--red); color: var(--red); }
.btn:disabled { opacity: .6; cursor: wait; }

/* ---------- Alert / badge ---------- */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; background: var(--info-soft); color: var(--info); font-weight: 500; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.err { background: var(--red-soft); color: var(--red-dark); }
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: .78rem; font-weight: 700; white-space: nowrap; background: #e4e4e7; color: #3f3f46; }
.st-inviato, .st-ricevuto { background: var(--warn-soft); color: var(--warn); }
.st-in_lavorazione, .st-confermato, .st-in_produzione { background: var(--info-soft); color: var(--info); }
.st-risposto, .st-pronto { background: var(--red); color: #fff; }
.st-accettato, .st-consegnato { background: var(--ok-soft); color: var(--ok); }
.st-rifiutato, .st-annullato { background: #e4e4e7; color: #71717a; }
.new { display: inline-block; font-size: .65rem; font-weight: 800; background: var(--red); color: #fff; border-radius: 4px; padding: 1px 5px; vertical-align: middle; }
.empty { color: var(--muted); padding: 10px 0; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; color: var(--ink); box-shadow: var(--shadow); display: flex; flex-direction: column; }
a.kpi:hover { text-decoration: none; border-color: var(--red); }
.kpi span { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi strong { font-size: 1.7rem; line-height: 1.2; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); font-size: .82rem; }
.kpi.accent { background: var(--black); border-color: var(--black); color: #fff; }
.kpi.accent span, .kpi.accent small { color: #a1a1aa; }
.kpi.accent strong { color: #fff; }
.bigactions { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.bigbtn { display: flex; align-items: center; gap: 14px; padding: 22px; border-radius: var(--radius); background: #fff; border: 2px solid var(--black); color: var(--black); font-size: 1.2rem; font-weight: 700; }
.bigbtn span { font-size: 1.8rem; line-height: 1; }
.bigbtn:hover { text-decoration: none; background: #fafafa; }
.bigbtn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.bigbtn.primary:hover { background: var(--red-dark); }

/* ---------- Tabelle ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.list { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.list th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
table.list th.r { text-align: right; }
table.list td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tbody tr[onclick] { cursor: pointer; }
table.list tbody tr:hover { background: #fafafa; }
table.list tr.unread td { background: #fff7f7; }
table.list tr.unread td:first-child { box-shadow: inset 3px 0 0 var(--red); }
table.list tr.disabled { opacity: .5; }
table.list tr.zero td { color: #a1a1aa; }
table.list tr.selected td { background: var(--red-soft); }
table.list tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--red); }
table.list tfoot td { padding: 11px 10px; border-top: 2px solid var(--ink); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px; }
.filters select, .filters input { width: auto; flex: 1 1 160px; margin: 0; }
.filters input[type=search] { flex: 2 1 220px; }

/* ---------- Modulo documento ---------- */
.item { border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 14px; background: #fcfcfc; }
.item-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }
.item-n { display: inline-block; background: var(--black); color: #fff; font-size: .78rem; font-weight: 700; padding: 3px 10px; border-radius: 6px; text-transform: uppercase; letter-spacing: .04em; }
.sizes-wrap { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 14px; }
.sizes-wrap .lbl { font-size: .85rem; font-weight: 600; color: #3f3f46; }
.sizes { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; margin-top: 8px; }
.size { margin: 0; text-align: center; }
.size span { display: block; font-weight: 800; color: var(--black); }
.size input { text-align: center; margin-top: 3px; padding: 8px 4px; font-weight: 700; }
.custs-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; border-top: 1px dashed #d4d4d8; padding-top: 6px; margin-top: 6px; }
.custs-head h3 { margin: 8px 0; }
.cust { border-left: 4px solid var(--red); background: #fff; border-radius: 8px; padding: 12px 12px 4px; margin-bottom: 10px; box-shadow: var(--shadow); }
.cust-foot { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.cust-foot input { margin: 0; }
.submitbar {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--black); color: #fff; padding: 12px 18px; border-radius: var(--radius);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  box-shadow: 0 -4px 20px rgba(0,0,0,.15);
}

/* ---------- Dettaglio documento ---------- */
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.doc-head h1 { margin-bottom: .2em; }
.back { font-size: .9rem; color: var(--muted); }
.meta { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: .9rem; margin-bottom: 18px; }
.info { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 20px; margin: 0; }
.info dt { font-size: .75rem; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.info dd { margin: 0; }
.notes { margin-top: 14px; padding: 12px; background: var(--warn-soft); border-radius: 8px; }
.item.view .item-head { margin-bottom: 8px; }
.sizechips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.sizechips span { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 3px 10px; font-size: .9rem; }
.custtable { width: 100%; border-collapse: collapse; font-size: .9rem; background: #fff; border-radius: 8px; overflow: hidden; }
.custtable th { background: var(--black); color: #fff; text-align: left; padding: 7px 10px; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; }
.custtable td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.totals { display: flex; justify-content: flex-end; gap: 24px; flex-wrap: wrap; padding-top: 10px; font-size: 1.05rem; }
.totals .comm { color: var(--ok); }
.response { border: 2px dashed #d4d4d8; }
.response.has { border: 2px solid var(--red); background: linear-gradient(0deg, #fff, var(--red-soft)); }
.files { display: flex; flex-wrap: wrap; gap: 10px; }
.file { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px 6px 6px; background: #fff; color: var(--ink); max-width: 100%; font-size: .9rem; }
.file:hover { border-color: var(--red); text-decoration: none; }
.file img { width: 44px; height: 44px; object-fit: contain; background: #f4f4f5; border-radius: 4px; }
.file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ficon { display: inline-flex !important; align-items: center; justify-content: center; width: 44px; height: 44px; background: var(--black); color: #fff; border-radius: 4px; font-size: .7rem; font-weight: 800; }
.files.big .file { padding: 10px 18px 10px 10px; font-size: 1rem; font-weight: 600; }
.outcome { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.outcome form { display: flex; gap: 8px; flex-wrap: wrap; }
.outcome .convert { flex: 1 1 400px; justify-content: flex-end; }
.outcome .convert input { width: auto; flex: 1 1 200px; margin: 0; }
.adminbox { border-top: 4px solid var(--black); }
.creds { border: 2px solid var(--ok); background: var(--ok-soft); }
.creds textarea { font-family: ui-monospace, Consolas, monospace; font-size: .9rem; margin-bottom: 10px; background: #fff; }
.override { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; margin: 6px 0 14px; }
.override label { margin: 0; display: flex; align-items: center; gap: 8px; }
.override label.check { margin: 0; }
.thread { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.msg { max-width: 80%; padding: 10px 14px; border-radius: 12px; background: #f4f4f5; }
.msg.from-admin { align-self: flex-start; background: var(--black); color: #fff; }
.msg.from-agent { align-self: flex-end; background: var(--red-soft); }
.msg .who { font-size: .75rem; opacity: .7; margin-bottom: 2px; }
.msgform textarea { margin-bottom: 8px; }
.msgform input[type=file] { width: auto; flex: 1; margin: 0; }
.danger-zone { text-align: right; }

/* ---------- Login ---------- */
body.auth { background: #000; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-box { width: 100%; max-width: 400px; text-align: center; }
.auth-logo { width: 220px; max-width: 70%; margin-bottom: 10px; }
.auth-box h1 { color: #fff; font-weight: 300; letter-spacing: .1em; text-transform: uppercase; font-size: 1.1rem; margin-bottom: 20px; }
.auth-box .card { text-align: left; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .cols { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 960px) {
  .menu-btn { display: block; }
  .mainnav { display: none; position: absolute; top: 100%; left: 0; right: 0; background: var(--black); flex-direction: column; align-items: stretch; padding: 8px; border-bottom: 3px solid var(--red); }
  .nav-open .mainnav { display: flex; }
  .mainnav a { padding: 14px; font-size: 1.05rem; }
}
@media (max-width: 760px) {
  .wrap { padding: 16px 12px 120px; }
  .card { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .bigactions { grid-template-columns: 1fr; }
  .kpi strong { font-size: 1.35rem; }
  .msg { max-width: 92%; }
  .custtable thead { display: none; }
  .custtable tr { display: block; border-bottom: 2px solid var(--line); padding: 4px 0; }
  .custtable td { display: flex; gap: 10px; border: 0; padding: 4px 10px; }
  .custtable td::before { content: attr(data-l); min-width: 80px; font-size: .75rem; color: var(--muted); text-transform: uppercase; }
}
@media (max-width: 480px) {
  .grid3 { grid-template-columns: 1fr 1fr; }
  .kpis { grid-template-columns: 1fr; }
  .brand span { display: none; }
}

/* ---------- Stampa ---------- */
@media print {
  .topbar, .foot, .btns, .adminbox, .msgform, .danger-zone, .outcome, .back, .menu-btn { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .wrap { padding: 0; }
}
