@import url('https://fonts.googleapis.com/css2?family=Amazon+Ember:wght@400;700&family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #f0f2f2;
  --panel: #ffffff;
  --line: #d5d9d9;
  --text: #0f1111;
  --muted: #565959;
  --accent: #c7511f;
  --accent2: #e77600;
  --blue: #007185;
  --blue-hover: #c9e6ef;
  --nav: #131921;
  --nav-hover: #3a4553;
  --btn-primary: #ffd814;
  --btn-primary-hover: #f7ca00;
  --btn-secondary: #fff3e0;
  --btn-secondary-border: #ffa41c;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.12);
  --shadow: 0 2px 8px rgba(0,0,0,.15);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.18);
  --r: 8px;
  --r-sm: 4px;
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ============================
   TOP NAV BAR (Amazon-style)
   ============================ */
.topbar {
  background: var(--nav);
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
}

.topbar-main {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  flex-direction: column;
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  white-space: nowrap;
  padding: 4px 8px;
  border: 2px solid transparent;
  border-radius: var(--r-sm);
  transition: border-color .15s;
}
.brand:hover { border-color: #fff; }
.brand small { font-size: 10px; font-weight: 400; letter-spacing: .5px; opacity: .8; }

.search-bar {
  flex: 1 1 320px;
  display: flex;
  max-width: 680px;
  border-radius: var(--r-sm);
  overflow: hidden;
  height: 40px;
}
.search-bar input {
  flex: 1;
  border: none;
  padding: 0 14px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  outline: none;
  background: #fff;
}
.search-bar input:disabled {
  background: #555;
  color: #999;
  cursor: not-allowed;
}
.search-bar input::placeholder { color: #999; }
.search-bar .search-btn {
  background: var(--accent2);
  border: none;
  width: 44px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  font-size: 17px;
}
.search-bar .search-btn:hover { background: #e59700; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  flex-wrap: wrap;
}

.nav-btn {
  color: #fff;
  background: transparent;
  border: 2px solid transparent;
  border-radius: var(--r-sm);
  padding: 4px 10px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.3;
  transition: border-color .15s;
  white-space: nowrap;
}
.nav-btn:hover { border-color: #fff; }
.nav-btn:disabled { opacity: .45; cursor: not-allowed; }
.nav-btn:disabled:hover { border-color: transparent; }
.nav-btn small { font-size: 11px; opacity: .75; }
.nav-btn b { font-size: 13px; }

.nav-btn.accent {
  background: var(--accent2);
  color: #000;
  border-color: var(--accent2);
  font-weight: 700;
}
.nav-btn.accent:hover { background: #e59700; border-color: #e59700; }

.auth-zone {
  display: flex;
  align-items: center;
  gap: 6px;
  border-left: 1px solid #3a4553;
  padding-left: 10px;
  margin-left: 4px;
}
.auth-zone input {
  background: #3a4553;
  border: 1px solid #4e5d6e;
  border-radius: var(--r-sm);
  color: #fff;
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  width: 130px;
  outline: none;
}
.auth-zone input::placeholder { color: #8a96a0; }
.auth-zone input:focus { border-color: var(--accent2); }
.auth-status {
  color: var(--accent2);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

/* Sub-nav strip */
.topbar-sub {
  background: #232f3e;
  padding: 0 12px;
  display: flex;
  gap: 2px;
  align-items: center;
  height: 36px;
  overflow: hidden;
}
.topbar-sub .sub-link {
  color: #fff;
  font-size: 13px;
  padding: 0 10px;
  height: 100%;
  display: flex;
  align-items: center;
  border: 2px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  white-space: nowrap;
  font-weight: 500;
  transition: border-color .15s;
}
.topbar-sub .sub-link.sub-link-dark {
  background: #000;
  color: #fff;
  border-color: #000;
  padding: 4px 12px;
  border-radius: var(--r-sm);
}
.topbar-sub .sub-link.sub-link-dark:hover { background: #222; border-color: #222; }
.topbar-sub .sub-link:hover { border-color: #fff; }
.topbar-sub .sub-link.active { border-color: var(--accent2); color: var(--accent2); }

/* ============================
   LAYOUT
   ============================ */
.layout {
  display: grid;
  grid-template-columns: 248px 1fr 380px;
  gap: 0;
  min-height: calc(100vh - 80px);
}

/* When commerciale is logged in: same cart size as omaggi */
body.role-commerciale .shipmentCartGrid {
  grid-template-columns: 1fr 90px 80px auto;
}

/* Commerciale: taller product list, compressed form */
body.role-commerciale .cart-items {
  flex: 2.5;
  min-height: 0;
}
body.role-commerciale .cart-form {
  flex-shrink: 1;
  overflow-y: auto;
  max-height: 55vh;
}
body.role-commerciale .cart-form .row {
  margin-bottom: 5px;
}
body.role-commerciale .cart-form input {
  padding: 5px 8px;
  font-size: 12px;
}
body.role-commerciale #comm-send-mode {
  padding: 7px 10px;
  font-size: 12px;
}

/* ============================
   LEFT SIDEBAR
   ============================ */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 12px;
  overflow-y: auto;
  max-height: calc(100vh - 80px);
  position: sticky;
  top: 80px;
}

.sidebar-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}

.cat-search-wrap {
  position: relative;
  margin-bottom: 12px;
}
.cat-search-wrap svg {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
}
#catSearch {
  width: 100%;
  padding: 7px 10px 7px 30px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font: inherit;
  font-size: 13px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
#catSearch:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(0,113,133,.15); }

.categoryList { display: flex; flex-direction: column; gap: 2px; }

.cat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .12s, border-color .12s;
  user-select: none;
}
.cat:hover { background: var(--blue-hover); border-color: #b3d8e0; }
.cat.active {
  background: #e8f4f8;
  border-color: var(--blue);
  border-left: 3px solid var(--blue);
}
.catName {
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
  flex: 1;
}
.cat.active .catName { color: var(--blue); font-weight: 700; }
.catBtns { display: flex; gap: 4px; opacity: 0; transition: opacity .12s; }
.cat:hover .catBtns { opacity: 1; }

.catSeparator {
  height: 1px;
  background: var(--line);
  margin: 8px 4px;
}

.sidebar-note {
  font-size: 11px;
  color: var(--muted);
  margin-top: 14px;
  line-height: 1.5;
  padding: 8px;
  background: #f8f9f9;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
}
.sidebar-note code {
  background: #e8eced;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 11px;
}

/* ============================
   CONTENT AREA
   ============================ */
.content {
  padding: 12px;
  overflow-y: auto;
  min-height: calc(100vh - 80px);
}

.content-header {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 10px 14px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}
.filter-breadcrumb {
  font-size: 13px;
  color: var(--muted);
}
.filter-breadcrumb strong { color: var(--text); }
.results-count {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

/* ============================
   PRODUCT GRID
   ============================ */
#productGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

/* ============================
   PRODUCT CARD (Amazon-style)
   ============================ */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow .2s, transform .15s;
  cursor: default;
  position: relative;
}
.card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

/* Status badges */
.card-status-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 999px;
  letter-spacing: .3px;
}

.thumb {
  background: #f8f9f9;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  min-height: 160px;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  position: relative;

  background-image: url("media/prodotti-bg.webp");
  background-size: cover;
  background-position: center;
}
.thumbImg {
  width: 100%;
  height: auto;
  max-height: 180px;
  object-fit: contain;
  display: none;
  transition: transform .3s;
}
.card:hover .thumbImg { transform: scale(1.03); }
.thumbEmpty {
  color: #bbbfbf;
  font-size: 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.thumbEmpty::before {
  content: '📦';
  font-size: 32px;
  opacity: .5;
}

.cardBody {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.cardTop {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.pName {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-overflow: hidden;
  overflow: hidden;
}
.pName:hover { color: var(--accent); }

.pCat {
  font-size: 11px;
  color: var(--blue);
  font-weight: 500;
}

/* Stock line */
.stockLine {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.stockTotal {
  font-size: 13px;
  font-weight: 700;
  color: #007600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.stock-zero { color: #cc0c39 !important; }
.stock-low { color: #e47911 !important; }

/* CT Pills */
.ct-container { display: flex; gap: 4px; flex-wrap: wrap; }
.ct-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 3px;
  border: 1px solid;
  line-height: 1.4;
  white-space: nowrap;
}
.ct-pill-full { background: #fff3cd; border-color: #ffc107; color: #856404; }
.ct-pill-partial { background: #e2e6ea; border-color: #adb5bd; color: #495057; }

.statusDots { display: flex; gap: 4px; margin-left: auto; }
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.15);
}
.dot.expired { background: #b71c1c; }
.dot.expiring { background: #f44336; }
.dot.risky { background: #e65100; }
.dot.ordered { background: #1b5e20; }

/* Action buttons */
.btnRow {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

/* Card status variants */
.card.cardOut { background: #fafafa; }
.card.cardOut .thumb { background: #f0f0f0; }
.card.cardOut .thumbImg { filter: grayscale(1); opacity: .6; }
.card.cardOut .pName { color: #888; }

.card.cardExpired { border: 2px solid #d32f2f; background: #fff5f5; }
.card.cardExpired .thumb { background: #ffeaea; }
.card.cardExpiring { border: 2px solid #ef5350; background: #fff8f8; }
.card.cardRisky { border: 2px solid #e64a19; background: #fff8f5; }
.card.cardLow { border: 2px solid #ffa000; background: #fffdf0; }
.card.cardOrdered { border: 2px solid #2e7d32; background: #f0faf0; }

/* Prodotto con TUTTI i lotti scaduti → bordo rosso prominente */
.card.cardAllExpired {
  border: 3px solid #c62828 !important;
  box-shadow: 0 0 0 2px rgba(198,40,40,0.18), 0 2px 8px rgba(198,40,40,0.12);
}

/* ============================
   RIGHT CART PANEL
   ============================ */
.cart-sidebar {
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  max-height: calc(100vh - 80px);
  position: sticky;
  top: 80px;
  display: flex;
  flex-direction: column;
}

.cart-header {
  background: var(--nav);
  color: #fff;
  padding: 12px 14px;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.cart-header-icon { font-size: 20px; }
.cart-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: auto;
}

.cart-overview {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #f8f9f9;
}
.cart-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}
.cart-stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 7px 4px;
  text-align: center;
}
.cart-stat b { display: block; font-size: 15px; color: var(--accent); }
.cart-stat span { font-size: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }

.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cart-empty {
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.cart-empty-icon { font-size: 36px; opacity: .4; }

.cart-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 10px;
  transition: box-shadow .15s;
}
.cart-item:hover { box-shadow: var(--shadow-sm); }

.shipmentCartItemTop {
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: 10px;
  align-items: start;
}
.shipmentCartThumb {
  width: 60px; height: 60px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: #f8f9f9;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding: 4px;
}
.shipmentCartThumb img, .shipmentCartThumbImg { width: 100%; height: 100%; object-fit: contain; }
.shipmentCartThumb.is-empty { color: #ccc; font-size: 10px; }

.shipmentCartItemHead {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 8px;
}
.shipmentCartItemName { font-weight: 700; font-size: 13px; line-height: 1.3; }
.shipmentCartItemSub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.shipmentCartGrid {
  display: grid;
  grid-template-columns: 1fr 80px 70px auto;
  grid-template-rows: auto auto;
  gap: 6px;
  align-items: end;
}
/* Lot select spans full width on its own row */
.shipmentCartGrid .row:first-child {
  grid-column: 1 / -1;
}
.shipmentCartGrid .row:first-child select {
  width: 100%;
  min-width: 0;
}
.shipmentCartGrid .row { margin-bottom: 0; }
.shipmentCartGrid .row span { font-size: 11px; font-weight: 600; color: var(--muted); }
.shipmentCartGrid input, .shipmentCartGrid select {
  padding: 6px 8px;
  font-size: 12px;
}

.cartMiniBtns { display: flex; gap: 4px; align-items: center; }
.cartMiniBtns .btn { min-width: 28px; padding: 6px 0; justify-content: center; }

.shipmentCartMeta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.4;
}
.shipmentCartMeta.is-error { color: #cc0c39; font-weight: 600; }

/* Cart form */
.cart-form {
  padding: 12px;
  border-top: 2px solid var(--line);
  background: #fafafa;
}
.cart-form-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 10px;
}

/* ============================
   BUTTONS
   ============================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: linear-gradient(to bottom, #f7f8fa, #e8eaed);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  transition: all .12s;
}
.btn:hover { background: linear-gradient(to bottom, #e8eaed, #dde0e4); border-color: #adb5bd; }
.btn:active { transform: scale(.98); }

.btn.ghost {
  background: #fff;
  border-color: #d5d9d9;
}
.btn.ghost:hover { background: #f0f2f2; }

.btn.small {
  padding: 5px 9px;
  font-size: 12px;
}

.btn.danger {
  color: #cc0c39;
  border-color: #f5c6d0;
  background: #fff5f7;
}
.btn.danger:hover { background: #fde0e7; }

.btn.primary {
  background: linear-gradient(to bottom, #ffe259, #ffd814);
  border-color: #c8a600;
  color: #111;
}
.btn.primary:hover { background: linear-gradient(to bottom, #f7ca00, #e9bc00); }

.btn.order {
  background: linear-gradient(to bottom, #d4edda, #c3e6cb);
  border-color: #28a745;
  color: #155724;
}
.btn.order:hover { background: linear-gradient(to bottom, #c3e6cb, #b1dfbb); }

.btn.received {
  background: linear-gradient(to bottom, #cce5ff, #b8d8f8);
  border-color: #007bff;
  color: #004085;
}
.btn.received:hover { background: linear-gradient(to bottom, #b8d8f8, #a2cafe); }

.btn[disabled] {
  opacity: .5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Full width cart action button */
#btnCreateShipment {
  width: 100%;
  padding: 11px;
  font-size: 15px;
  background: linear-gradient(to bottom, #ffd814, #f7ca00);
  border: 1px solid #c8a600;
  color: #111;
  border-radius: 20px;
  font-weight: 700;
  letter-spacing: .2px;
  cursor: pointer;
  transition: all .15s;
  margin-bottom: 8px;
}
#btnCreateShipment:hover { background: linear-gradient(to bottom, #f7ca00, #e9bc00); }

.cart-action-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.cart-action-row .btn { flex: 1; font-size: 12px; padding: 7px; }

/* ============================
   FORMS / INPUTS
   ============================ */
input, textarea, select {
  border: 1px solid #888c8c;
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  border-color: #e77600;
  box-shadow: 0 0 0 3px rgba(231,118,0,.2);
}
textarea { resize: vertical; }
input::placeholder { color: #aaa; }
input:disabled { background: #f8f9f9; color: #999; cursor: not-allowed; }

.row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}
.row > span, .row > label > span {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .4px;
}

/* ============================
   DIALOGS
   ============================ */
.dlg::backdrop { background: rgba(15,17,17,.55); backdrop-filter: blur(2px); }
.dlg {
  border: none;
  background: transparent;
  padding: 0;
  /* Centered on screen */
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  max-height: 90vh;
  overflow-y: auto;
}
.dlgBody {
  width: min(560px, calc(100vw - 24px));
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  padding: 20px;
}
.dlgBody.wide { width: min(900px, calc(100vw - 24px)); }
.dlgTitle {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--line);
  display: flex;
  align-items: center;
  gap: 8px;
}
.dlgTitle::before {
  content: '';
  display: block;
  width: 4px;
  height: 20px;
  background: var(--accent);
  border-radius: 2px;
}

.dlgBtns {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.dlgBtnsSplit { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.dlgBtnsRight { display: flex; justify-content: flex-end; gap: 8px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ============================
   STOCK DIALOG
   ============================ */
.stockGrid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 12px; margin-top: 12px; }
.panel {
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px;
  background: #fafbfc;
}
.panelTitle { font-weight: 700; font-size: 13px; margin-bottom: 10px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }

#lotList { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }

.lotRow {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 10px;
  background: #fff;
}
.lotMeta { display: flex; flex-direction: column; gap: 2px; }
.lotExp { font-weight: 700; font-size: 14px; }
.lotQty { color: var(--muted); font-size: 12px; }

.lotRow.lotExpired { background: #fff5f5; border-left: 4px solid #d32f2f; }
.lotRow.lotExpiring { background: #fff8f8; border-left: 4px solid #ef5350; }
.lotRow.lotRisky { background: #fff8f5; border-left: 4px solid #e64a19; }
.lotRow.lotOrdered { background: #f0faf0; border-left: 4px solid #2e7d32; }

/* Lot items in info dialog */
.lotsBox { border: 1px solid var(--line); border-radius: var(--r); background: #fafbfc; padding: 8px; max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.lotsWrap { grid-column: 1 / -1; }
.lotItem {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: #fff;
  font-size: 12px;
}
.lotItem.lotExpired { background: #fff5f5; border-left: 4px solid #d32f2f; }
.lotItem.lotExpiring { background: #fff8f8; border-left: 4px solid #ef5350; }
.lotItem.lotRisky { background: #fff8f5; border-left: 4px solid #e64a19; }

.lotMain { display: flex; flex-direction: column; gap: 3px; }
.lotQtyBig { font-weight: 900; color: var(--text); font-size: 14px; display: flex; align-items: center; gap: 6px; }
.lotDateSmall { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.lotTag {
  font-weight: 700;
  border-radius: 3px;
  padding: 2px 7px;
  font-size: 10px;
  letter-spacing: .3px;
  background: #e8eced;
  color: #565959;
  border: 1px solid var(--line);
}
.lotRow.lotExpired .lotTag, .lotItem.lotExpired .lotTag { background: #d32f2f; color: #fff; border-color: #d32f2f; }
.lotRow.lotExpiring .lotTag, .lotItem.lotExpiring .lotTag { background: #ef5350; color: #fff; border-color: #ef5350; }
.lotRow.lotRisky .lotTag, .lotItem.lotRisky .lotTag { background: #e64a19; color: #fff; border-color: #e64a19; }
.lotRow.lotOrdered .lotTag { background: #2e7d32; color: #fff; border-color: #2e7d32; }

/* Image editor row */
.imgRow { display: grid; grid-template-columns: 160px 1fr; gap: 14px; align-items: start; margin-top: 8px; }
.imgBox {
  height: 130px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: #f8f9f9;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
}
.imgBox img { width: 100%; height: 100%; object-fit: contain; }
.imgSide { display: flex; flex-direction: column; gap: 8px; }

/* Checkbox list */
.checkList {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: #fff;
  padding: 8px;
  max-height: 160px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.checkItem {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  padding: 3px 4px;
  border-radius: 3px;
  transition: background .1s;
}
.checkItem:hover { background: #f0f2f2; }
.checkItem input[type="checkbox"] { width: auto; margin: 0; cursor: pointer; }

/* Misc info dialog */
.miscGrid { margin-top: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.miscTitle { font-weight: 700; font-size: 12px; margin-bottom: 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.miscBox {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 10px;
  background: #fafbfc;
  color: var(--muted);
  font-size: 12px;
  white-space: pre-wrap;
  margin: 0;
  min-height: 40px;
  font-family: inherit;
}

/* Shipment history */
.shipHistTools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.shipHistBody { width: min(1100px, calc(100vw - 24px)); }
.shipTableWrap {
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: auto;
  max-height: 60vh;
  background: #fff;
}
.shipTable { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 900px; }
.shipTable th, .shipTable td { padding: 10px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.shipTable thead th { position: sticky; top: 0; background: #f0f2f2; z-index: 1; font-weight: 700; text-transform: uppercase; font-size: 11px; letter-spacing: .4px; color: var(--muted); }
.shipTable tr:hover td { background: #fafbfc; }
.shipDel { text-align: right; }
.shipEmpty { padding: 24px; text-align: center; color: var(--muted); }
.shipRowActions { display: flex; flex-wrap: wrap; gap: 5px; justify-content: flex-end; }

/* Empty state */
.empty {
  padding: 32px;
  color: var(--muted);
  border: 2px dashed var(--line);
  border-radius: var(--r);
  text-align: center;
  background: var(--panel);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.empty::before { content: '🔍'; font-size: 32px; }

/* Rowbtns */
.rowBtns { display: flex; gap: 8px; flex-wrap: wrap; }

/* Small note */
.smallNote { font-size: 12px; color: var(--muted); margin-top: 8px; line-height: 1.5; }

/* ============================
   SHIPMENT CART FORM
   ============================ */
.shipmentCartPanel {
  display: contents;
}

.cart-form .grid2 { gap: 8px; }
.cart-form .row { margin-bottom: 8px; }
.cart-form .row > span { font-size: 11px; }
.cart-form input { padding: 7px 9px; font-size: 13px; }
.cart-form .checkItem { font-size: 12px; }

.cartCheckRow { justify-content: flex-start; }

/* ============================
   SCROLLBARS
   ============================ */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: #f0f2f2; }
::-webkit-scrollbar-thumb { background: #c9cbcb; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #a0a4a4; }

/* ============================
   RESPONSIVE
   ============================ */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 220px 1fr 290px; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar, .cart-sidebar { position: static; max-height: none; border: none; }
  .sidebar { border-bottom: 1px solid var(--line); }
  .cart-sidebar { border-top: 1px solid var(--line); }
  .content { order: -1; }
  .topbar-main { flex-wrap: wrap; }
  .auth-zone { border-left: none; padding-left: 0; margin-left: 0; flex-wrap: wrap; }
  .auth-zone input { width: 100px; }
  .grid2, .stockGrid, .imgRow, .miscGrid { grid-template-columns: 1fr; }
  #productGrid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .shipmentCartGrid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  /* Mostra la topbar-sub solo per i bottoni scanner, nascondi il resto */
  .topbar-sub .sub-link-dark,
  .topbar-sub #fileNote,
  .topbar-sub #btnOpenFolder,
  .topbar-sub #folderStatus,
  .topbar-sub #btnLoad,
  .topbar-sub #importExcelPicker { display: none !important; }
  /* Nascondi la barra se nessun bottone scanner è attivo */
  .topbar-sub[data-scanner-visible="0"] { display: none; }
  /* Layout compatto per la barra scanner */
  .topbar-sub {
    padding: 6px 10px;
    gap: 6px;
    flex-wrap: nowrap;
    justify-content: center;
    min-height: 0;
  }
  .sub-link-scan {
    font-size: 12px;
    padding: 6px 10px;
  }
  .search-bar { flex-basis: 100%; max-width: 100%; order: 3; }
  #productGrid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .thumb { min-height: 120px; }
  .dlgBody, .dlgBody.wide { width: calc(100vw - 16px); padding: 14px; }
}

/* ============================
   DISCONTINUED styles
   ============================ */
.disc-badge {
  display: inline-block;
  background: #c0392b;
  color: #fff;
  border-radius: 3px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
  margin-left: 6px;
  vertical-align: middle;
  white-space: nowrap;
}

.cardDiscontinued {
  opacity: 0.75;
  border: 2px solid #c0392b !important;
}

.cardDiscontinued .stockTotal {
  color: #c0392b !important;
}

.btn-backorder {
  background: linear-gradient(to bottom, #f0ad4e, #e8971a) !important;
  border-color: #d68910 !important;
  color: #fff !important;
}

/* ============================
   CUSTOM MODAL (replaces alert/confirm)
   ============================ */
.custom-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 9999;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 16px 16px;
}
.custom-modal-box {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.28);
  max-width: 460px;
  width: 100%;
  padding: 28px 28px 20px;
  font-family: var(--font);
  animation: modalIn .15s ease;
}
@keyframes modalIn {
  from { transform: translateY(-12px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}
.custom-modal-body {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  margin-bottom: 20px;
}
.custom-modal-btns {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.custom-modal-btns .btn { min-width: 80px; }

/* ============================
   COMMERCIALE INFO BANNER
   ============================ */
.comm-info-banner {
  background: linear-gradient(90deg, #eaf4fb 0%, #d6eaf8 100%);
  border-bottom: 1px solid #aed6f1;
  color: #1a5276;
  font-size: 13px;
  padding: 9px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  line-height: 1.5;
}
.comm-info-icon {
  font-size: 16px;
  flex-shrink: 0;
}

/* =====================================================================
   BARCODE SCANNER MODULE
   ===================================================================== */

/* Topbar scan buttons */
.sub-link-scan {
  background: rgba(46,204,113,.15);
  color: #27ae60;
  border: 1px solid rgba(46,204,113,.35);
  font-weight: 600;
}
.sub-link-scan:hover {
  background: rgba(46,204,113,.28);
  color: #1e8449;
}
.sub-link-scan-danger {
  background: rgba(231,76,60,.12);
  color: #c0392b;
  border-color: rgba(231,76,60,.3);
}
.sub-link-scan-danger:hover {
  background: rgba(231,76,60,.22);
  color: #a93226;
}

/* Overlay backdrop */
#barcodeOverlay {
  display: none;
  position: fixed; inset: 0; z-index: 1100;
  background: rgba(0,0,0,.62);
  align-items: center; justify-content: center;
  padding: 12px;
}

/* Main panel */
.bc-panel {
  background: var(--surface, #fff);
  border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0,0,0,.35);
  width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
  display: flex; flex-direction: column;
  animation: modalIn .18s ease;
}

.bc-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border, #e0e0e0);
}
.bc-title {
  font-size: 15px; font-weight: 700; color: var(--text, #1a1a2e);
}
.bc-close {
  background: none; border: none; font-size: 18px; cursor: pointer;
  color: var(--text2, #777); padding: 4px 8px; border-radius: 6px;
  line-height: 1;
}
.bc-close:hover { background: var(--surface2, #f0f0f0); }

/* Mode buttons */
.bc-modes {
  display: flex; gap: 6px; padding: 12px 16px 8px;
  flex-wrap: wrap;
}
.bc-mode-btn {
  flex: 1; padding: 8px 10px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border, #ddd); border-radius: 8px;
  background: var(--surface2, #f5f5f5); color: var(--text2, #555);
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.bc-mode-btn:hover { background: var(--surface3, #eee); }
.bc-mode-btn.active {
  background: var(--accent, #2979ff); color: #fff;
  border-color: var(--accent, #2979ff);
}

/* Camera */
.bc-cam-wrap {
  position: relative; margin: 6px 16px;
  border-radius: 10px; overflow: hidden;
  background: #000; aspect-ratio: 4/3;
  max-height: 240px;
}
#bcVideo {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.bc-crosshair {
  position: absolute; inset: 0; pointer-events: none;
  border: 2px solid rgba(41,121,255,.7);
  box-shadow: inset 0 0 0 9999px rgba(0,0,0,.25);
}
.bc-crosshair::before, .bc-crosshair::after {
  content: ''; position: absolute;
  background: rgba(41,121,255,.9);
}
.bc-crosshair::before { left: 50%; top: 20%; bottom: 20%; width: 1.5px; transform: translateX(-50%); }
.bc-crosshair::after  { top: 50%; left: 20%; right: 20%; height: 1.5px; transform: translateY(-50%); }

/* Manual input row */
.bc-manual-row {
  display: flex; gap: 8px; padding: 8px 16px;
}
.bc-manual-row input {
  flex: 1; padding: 8px 10px; border: 1px solid var(--border, #ddd);
  border-radius: 8px; font-size: 14px;
}

/* Result */
.bc-result {
  margin: 4px 16px 8px; padding: 10px 12px;
  border-radius: 8px; font-size: 13px; line-height: 1.6;
  min-height: 0; transition: all .15s;
}
.bc-result:empty { padding: 0; margin-bottom: 0; }
.bc-result-ok   { background: #eafaf1; border: 1px solid #a9dfbf; color: #1e8449; }
.bc-result-warn { background: #fef9e7; border: 1px solid #f9e79f; color: #7d6608; }
.bc-result-info { background: #eaf4fb; border: 1px solid #aed6f1; color: #1a5276; }

/* Check stock table */
.bc-check-name {
  font-weight: 700; font-size: 15px; margin-bottom: 4px;
}
.bc-check-total {
  font-size: 14px; margin-bottom: 8px; font-weight: 600; color: #27ae60;
}
.bc-check-total.stock-zero { color: #c0392b; }
.bc-check-total.stock-low  { color: #e67e22; }
.bc-lot-table {
  width: 100%; border-collapse: collapse; font-size: 12px;
}
.bc-lot-table th, .bc-lot-table td {
  padding: 5px 8px; text-align: left;
  border-bottom: 1px solid rgba(0,0,0,.08);
}
.bc-lot-table th { font-weight: 700; color: var(--text2, #666); }
.bc-st-badge {
  display: inline-block; padding: 2px 6px; border-radius: 4px;
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
}
.bc-st-ok       { background: #d5f5e3; color: #1e8449; }
.bc-st-risky    { background: #fdebd0; color: #d35400; }
.bc-st-expiring { background: #fef9e7; color: #9a7d0a; }
.bc-st-expired  { background: #fadbd8; color: #922b21; }
.bc-st-unknown  { background: #eaf2ff; color: #2471a3; }

/* Remove form */
.bc-remove-form {
  display: flex; flex-direction: column; gap: 8px; margin-top: 6px;
}
.bc-remove-label {
  font-size: 12px; font-weight: 600; color: var(--text2, #666);
  display: flex; flex-direction: column; gap: 3px;
}
.bc-select, .bc-number-input {
  padding: 7px 9px; border: 1px solid var(--border, #ddd);
  border-radius: 7px; font-size: 13px; width: 100%;
}
.bc-remove-btns {
  display: flex; gap: 8px; margin-top: 4px;
}

/* Remove session list */
.bc-remove-title {
  font-size: 12px; font-weight: 700; color: var(--text2, #666);
  padding: 8px 16px 4px; border-top: 1px solid var(--border, #eee);
  margin-top: 4px;
}
.bc-remove-list {
  padding: 0 16px; display: flex; flex-direction: column; gap: 6px;
}
.bc-removed-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface2, #f8f8f8); border: 1px solid var(--border, #ddd);
  border-radius: 8px; padding: 8px 10px; gap: 8px;
}
.bc-removed-info { flex: 1; font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
.bc-removed-meta { font-size: 11px; color: var(--text2, #888); }
.bc-removed-btns { display: flex; gap: 6px; flex-shrink: 0; }
.bc-remove-actions {
  padding: 8px 16px 12px; display: flex; justify-content: flex-end;
}


/* ===== Barcode scanner enhancements ===== */
.bc-camera-tools{display:flex;gap:8px;margin-top:10px;flex-wrap:wrap}
.bc-camera-hint{margin-top:8px;font-size:12px;line-height:1.4;color:var(--text2, #5f6b76)}
.bc-status{margin-top:8px;padding:9px 12px;border-radius:10px;background:#f6f7f8;border:1px solid #e3e7ea;font-size:13px;color:#1f2937}
.bc-status-ok{background:#ecfdf5;border-color:#bbf7d0;color:#166534}
.bc-status-warn{background:#fff7ed;border-color:#fed7aa;color:#9a3412}
.bc-status-info{background:#eff6ff;border-color:#bfdbfe;color:#1d4ed8}
#bcTorchBtn[disabled]{opacity:.7;cursor:not-allowed}
