:root {
  --bg: #f3efe6;
  --bg-deep: #e7e0d2;
  --ink: #1c2a2e;
  --muted: #5d6b70;
  --line: rgba(28, 42, 46, 0.12);
  --panel: rgba(255, 252, 246, 0.88);
  --accent: #0f6e6a;
  --accent-ink: #f7fffe;
  --danger: #9b2c2c;
  --shadow: 0 18px 40px rgba(28, 42, 46, 0.08);
  --radius: 18px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(15, 110, 106, 0.12), transparent 34%),
    radial-gradient(circle at 88% 0%, rgba(176, 122, 64, 0.14), transparent 28%),
    linear-gradient(160deg, var(--bg), var(--bg-deep));
  background-attachment: fixed;
}

a {
  color: inherit;
  text-decoration: none;
}

.page {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.25rem 0 3rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  backdrop-filter: blur(10px);
}

.topbar-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: auto;
  flex: 0 1 auto;
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.nav-toggle {
  display: none;
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.28rem;
}

.nav-toggle span {
  display: block;
  width: 1.15rem;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.nav-toggle[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(5.5px) rotate(45deg);
}
.nav-toggle[aria-expanded="true"] span:nth-child(2) {
  opacity: 0;
}
.nav-toggle[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-5.5px) rotate(-45deg);
}

.nav {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  flex-wrap: wrap;
}

.nav a {
  color: var(--muted);
  font-weight: 500;
}

.nav a:hover,
.nav-muted {
  color: var(--ink);
}

.eyebrow {
  margin: 0 0 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
}

h1, h2 {
  font-family: var(--font-display);
  letter-spacing: -0.03em;
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 2.8rem);
  line-height: 1.05;
}

.lede, .hint {
  color: var(--muted);
  line-height: 1.5;
}

.lede {
  margin: 0.55rem 0 0;
  max-width: 40rem;
}

.flash {
  margin: 0 0 1rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
}

.flash-error {
  border-color: rgba(155, 44, 44, 0.35);
  background: #fff1f1;
  color: var(--danger);
}

.flash-success {
  border-color: rgba(15, 110, 106, 0.3);
  background: #eef8f7;
  color: var(--accent);
}

.flash-warn {
  border-color: rgba(180, 120, 20, 0.4);
  background: #fff8e8;
  color: #8a5a00;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.7rem 1.15rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: rgba(28, 42, 46, 0.25);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #f7fffe;
}

.btn-danger {
  background: #fff;
  border-color: rgba(155, 44, 44, 0.35);
  color: var(--danger);
}

.btn-ghost {
  background: transparent;
}

.auth-shell {
  min-height: calc(100vh - 4rem);
  display: grid;
  place-items: center;
}

.auth-panel {
  width: min(440px, 100%);
  padding: 2rem;
  border-radius: calc(var(--radius) + 4px);
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  animation: rise 0.5s ease both;
}

.stack {
  display: grid;
  gap: 0.9rem;
  margin-top: 1.25rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-weight: 600;
  font-size: 0.92rem;
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="file"],
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  font: inherit;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.meta-list {
  display: grid;
  gap: 0.55rem;
  margin: 0 0 1rem;
}

.meta-list div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--line);
}

.meta-list dt {
  color: var(--muted);
  font-weight: 500;
}

.meta-list dd {
  margin: 0;
  font-weight: 600;
}

.catalog-hero,
.form-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.online-count {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.55rem 0 0;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--muted);
}

.online-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #2f9e44;
  box-shadow: 0 0 0 0 rgba(47, 158, 68, 0.45);
  animation: online-pulse 2s ease-out infinite;
}

@keyframes online-pulse {
  0% { box-shadow: 0 0 0 0 rgba(47, 158, 68, 0.45); }
  70% { box-shadow: 0 0 0 0.45rem rgba(47, 158, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(47, 158, 68, 0); }
}

.search-bar {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1.4rem;
  flex-wrap: wrap;
  align-items: end;
}

.search-bar input {
  flex: 1 1 220px;
}

.sort-field {
  display: grid;
  gap: 0.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.filter-check {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.7rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}

.filter-check input {
  width: auto;
  margin: 0;
  accent-color: var(--accent);
}

.sort-field select {
  min-width: 160px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: #fff;
}

.filters {
  margin-bottom: 1.4rem;
}

.price-range {
  margin-top: 0.85rem;
  padding: 1rem 1.1rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.price-range-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.price-range-head strong {
  color: var(--accent);
  font-size: 1.05rem;
}

.price-slider {
  position: relative;
  height: 28px;
}

.price-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 6px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: rgba(28, 42, 46, 0.12);
}

.price-track-active {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: inherit;
  background: var(--accent);
}

.price-slider input[type="range"] {
  position: absolute;
  left: 0;
  width: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin: 0;
  appearance: none;
  background: none;
  pointer-events: none;
  height: 28px;
}

.price-slider input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  pointer-events: auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: var(--accent);
  box-shadow: 0 2px 8px rgba(28, 42, 46, 0.25);
  cursor: pointer;
}

.price-slider input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: var(--accent);
  box-shadow: 0 2px 8px rgba(28, 42, 46, 0.25);
  cursor: pointer;
}

.price-slider input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: transparent;
}

.price-slider input[type="range"]::-moz-range-track {
  height: 6px;
  background: transparent;
}

.price-scale {
  position: relative;
  height: 1.2rem;
  margin-top: 0.45rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.price-scale span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  white-space: nowrap;
}

.price-scale span:first-child {
  transform: translateX(0);
}

.price-scale span:last-child {
  transform: translateX(-100%);
}

.tile-cat {
  margin: 0.2rem 0 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.view-switch {
  display: inline-flex;
  gap: 0.35rem;
  margin: 0 0 0.85rem;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.view-switch-btn {
  min-height: 2.2rem;
  padding: 0.4rem 0.85rem;
  border-radius: 9px;
  box-shadow: none;
}

.view-switch-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #f7fffe;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.item-list {
  display: grid;
  gap: 0.35rem;
}

/* display:grid sopra batte [hidden] del browser */
.grid[hidden],
.item-list[hidden] {
  display: none !important;
}

.item-list-head,
.item-row {
  display: grid;
  grid-template-columns: 0.85rem 3.1rem minmax(4.5rem, 7.5rem) minmax(0, 1fr);
  gap: 0.65rem 0.75rem;
  align-items: center;
  padding: 0.45rem 0.65rem;
}

.item-list.has-price .item-list-head,
.item-list.has-price .item-row {
  grid-template-columns: 0.85rem 3.1rem minmax(4.5rem, 7.5rem) minmax(0, 1fr) 5.5rem;
}

.item-list-head {
  padding-bottom: 0.2rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.item-row {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.item-row:hover {
  border-color: rgba(15, 110, 106, 0.35);
  transform: translateY(-1px);
}

.item-list-thumb {
  width: 3.1rem;
  height: 3.1rem;
  border-radius: 8px;
  overflow: hidden;
  background: #dfe8e6;
  display: grid;
  place-items: center;
}

.item-list-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.item-list-no-photo {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.item-list-code {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-dup,
.item-list-code.code-dup {
  display: inline-block;
  max-width: 100%;
  padding: 0.12em 0.45em;
  border-radius: 4px;
  background: #c62828;
  color: #fff !important;
  font-weight: 700;
  line-height: 1.35;
  vertical-align: middle;
  box-sizing: border-box;
}

.item-list-code.code-dup {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-dup-hint {
  color: #b71c1c;
  margin: 0.25rem 0 0.5rem;
}

.code-dup-hint a {
  color: #b71c1c;
  text-decoration: underline;
}

.code-dup-label {
  font-style: normal;
  font-weight: 700;
  color: #c62828;
}

input.code-dup-input {
  background: #c62828 !important;
  color: #fff !important;
  border-color: #8e0000 !important;
}

input.code-dup-input::placeholder {
  color: rgba(255, 255, 255, 0.65);
}

.item-list-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-list-price {
  font-weight: 700;
  color: var(--accent);
  text-align: right;
  white-space: nowrap;
}

.item-list-dot {
  justify-self: center;
}

.tile {
  display: grid;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  box-shadow: var(--shadow);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
  animation: rise 0.45s ease both;
  user-select: text;
}

.tile:hover {
  transform: translateY(-4px);
  box-shadow: 0 22px 44px rgba(28, 42, 46, 0.12);
}

.tile-media {
  display: block;
  text-decoration: none;
  color: inherit;
  aspect-ratio: 1 / 1;
  background: #dfe8e6;
  overflow: hidden;
}

.tile-body h2 {
  margin: 0.35rem 0 0;
  font-size: 1.05rem;
  line-height: 1.25;
}

.tile-title {
  color: inherit;
  text-decoration: none;
}

.tile-title:hover {
  color: var(--accent);
}

.tile-media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
}

.tile-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  color: rgba(28, 42, 46, 0.35);
  font-size: 1.4rem;
}

.tile-body {
  padding: 0.9rem 1rem 1.1rem;
}

.tile-body h2 {
  font-size: 1.15rem;
  margin-top: 0.15rem;
}

.status-dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 0.35rem;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
  background: transparent;
}

.status-dot.is-off {
  background: transparent;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}

.status-dot.is-green { background: #22a35a; box-shadow: none; }
.status-dot.is-blue { background: #3b82f6; box-shadow: none; }
.status-dot.is-yellow { background: #e0b400; box-shadow: none; }
.status-dot.is-red { background: #d64545; box-shadow: none; }

.item-code-row {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}

.status-dot-picker {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0.35rem 0 0.75rem;
}

.status-dot-picker .hint {
  margin: 0 0.25rem 0 0;
  font-size: 0.8rem;
}

.status-dot-btn {
  appearance: none;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  background: #ccc;
}

.status-dot-btn.is-green { background: #22a35a; }
.status-dot-btn.is-blue { background: #3b82f6; }
.status-dot-btn.is-yellow { background: #e0b400; }
.status-dot-btn.is-red { background: #d64545; }
.status-dot-btn.is-off {
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.status-dot-btn.is-active {
  border-color: #222;
  transform: scale(1.12);
}

.tile-body .code {
  display: flex;
  align-items: center;
}

.code {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.price {
  margin: 0.45rem 0 0;
  font-weight: 700;
  color: var(--accent);
}

.empty {
  text-align: center;
  padding: 3rem 1rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(255, 252, 246, 0.55);
}

.back {
  display: inline-block;
  margin-bottom: 1rem;
  color: var(--muted);
  font-weight: 600;
}

.detail-layout {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 1.5rem;
  align-items: start;
}

.gallery,
.detail-info,
.item-form,
.inline-lookup {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.gallery {
  padding: 0.85rem;
}

.gallery-main {
  border-radius: 14px;
  overflow: hidden;
  background: #dfe8e6;
  aspect-ratio: 1 / 1;
}

.gallery-main img,
.gallery-empty {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
}

.gallery-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  min-height: 280px;
}

.thumbs {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.7rem;
  overflow-x: auto;
}

.thumb {
  border: 2px solid transparent;
  padding: 0;
  border-radius: 10px;
  overflow: hidden;
  width: 72px;
  height: 72px;
  cursor: pointer;
  background: none;
}

.thumb.is-active,
.thumb:hover {
  border-color: var(--accent);
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  background: #dfe8e6;
}

.detail-info {
  padding: 1.35rem;
}

.price-lg {
  margin: 0.7rem 0 1rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.numbering {
  margin: 0.45rem 0 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.detail-meta {
  display: grid;
  gap: 0.45rem;
  margin: 0.9rem 0 0;
}

.detail-meta div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--line);
}

.detail-meta dt {
  color: var(--muted);
  font-weight: 600;
}

.detail-meta dd {
  margin: 0;
  font-weight: 600;
  text-align: right;
}

.tile-numbering {
  margin: 0.25rem 0 0;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
}

.tile-linea,
.tile-misure,
.tile-anno {
  margin: 0.2rem 0 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.tile-anno {
  color: var(--ink);
}

.tile-notes {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.35;
  color: var(--muted);
  font-style: italic;
}

.prose h2,
.lookup h2 {
  font-size: 1.05rem;
  margin: 1rem 0 0.4rem;
}

.prose p {
  margin: 0;
  line-height: 1.55;
  white-space: pre-wrap;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.2rem;
}

.lookup {
  margin-top: 1.4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.lookup-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.7rem;
}

.form-page .item-form,
.form-page .inline-lookup {
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.photo-manage {
  margin: 1rem 0 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem;
}

.photo-manage legend {
  padding: 0 0.35rem;
  font-weight: 700;
}

.photo-manage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.7rem;
}

.photo-chip {
  display: grid;
  gap: 0.4rem;
  padding: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  cursor: grab;
}

.photo-chip.is-dragging {
  opacity: 0.55;
}

.photo-chip.drag-over {
  border-color: var(--accent);
}

.photo-chip.is-cover {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 110, 106, 0.15);
}

.photo-chip-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  min-height: 1.2rem;
}

.drag-handle {
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: -0.08em;
  user-select: none;
}

.cover-badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #f7fffe;
  background: var(--accent);
  border-radius: 999px;
  padding: 0.15rem 0.45rem;
}

.photo-move {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}

.photo-chip-actions {
  display: grid;
  gap: 0.35rem;
  font-weight: 500;
}

.photo-chip-actions .btn {
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  width: 100%;
}

.photo-chip-actions .btn-danger {
  background: #fff;
}

.crop-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: max(0.5rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-right)) max(0.5rem, env(safe-area-inset-bottom)) max(0.5rem, env(safe-area-inset-left));
  background: rgba(28, 42, 46, 0.55);
  overscroll-behavior: contain;
}

.crop-modal[hidden] {
  display: none !important;
}

.crop-dialog {
  width: min(920px, 100%);
  /* Altezza definita → crop-stage flex:1 ha spazio reale (toolbar Conferma sempre in vista) */
  height: min(860px, calc(100dvh - 1rem));
  max-height: calc(100dvh - 1rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--radius);
  background: #fffaf2;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 0.85rem;
  margin: auto;
  min-height: 0;
}

.crop-dialog-head {
  flex: 0 0 auto;
}

.crop-dialog-head h2 {
  font-size: 1.35rem;
  margin: 0;
}

.crop-aspects {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.75rem 0 0.25rem;
  flex: 0 0 auto;
}

.crop-aspects .btn.is-active,
.crop-toolbar .btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #f7fffe;
}

.crop-stage {
  position: relative;
  margin: 0.5rem 0;
  width: 100%;
  /* Flex fill: lascia spazio alla toolbar (Conferma ritaglio sempre visibile) */
  flex: 1 1 0;
  height: 0;
  min-height: 200px;
  max-height: none;
  background: #1c2a2e;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  isolation: isolate;
}

/* Immagine sorgente prima dell’avvio di Cropper */
.crop-stage > img {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

/* Cropper gestisce da solo width/height/transform: niente absolute/inset !important */
.crop-stage .cropper-container {
  max-width: 100%;
  max-height: 100%;
}

.crop-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  flex: 0 0 auto;
  padding-top: 0.45rem;
  background: #fffaf2;
  z-index: 5;
}

.crop-toolbar-tools,
.crop-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.crop-toolbar-tools {
  justify-content: flex-start;
}

.crop-toolbar-actions {
  justify-content: flex-end;
}

.crop-toolbar-actions .btn-primary {
  min-height: 2.75rem;
  min-width: min(100%, 14rem);
  font-weight: 700;
  font-size: 1.02rem;
}

.photo-chip img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  object-position: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #dfe8e6;
}

.paste-zone-wrap {
  display: grid;
  gap: 0.5rem;
}

.paste-zone {
  border: 2px dashed rgba(15, 110, 106, 0.35);
  border-radius: 14px;
  padding: 1rem 1.1rem;
  background: rgba(255, 252, 246, 0.75);
  outline: none;
  cursor: text;
  caret-color: var(--accent);
  min-height: 4.5rem;
}

.paste-zone:focus,
.paste-zone.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 110, 106, 0.15);
}

.paste-zone strong {
  display: block;
  margin-bottom: 0.25rem;
}

.paste-zone p {
  margin: 0.2rem 0;
  color: var(--muted);
  line-height: 1.4;
}

.paste-zone kbd {
  display: inline-block;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-size: 0.85em;
  color: var(--ink);
}

.paste-preview {
  margin-top: 0.75rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 0.5rem;
}

.paste-preview img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #dfe8e6;
}

.camera-box {
  display: grid;
  gap: 0.7rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 252, 246, 0.7);
}

.camera-label {
  font-weight: 600;
  font-size: 0.92rem;
}

.camera-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.camera-video {
  width: 100%;
  max-height: 360px;
  object-fit: cover;
  border-radius: 12px;
  background: #111;
}

.camera-shots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 0.5rem;
}

.camera-shot {
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  aspect-ratio: 1;
}

.camera-shot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.inline-lookup {
  margin-top: 0;
}

.lens-split {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 1rem;
  min-height: calc(100vh - 6rem);
  align-items: stretch;
}

.lens-compact {
  width: min(520px, 100%);
  margin: 0 auto;
  padding: 0.5rem 0 1.5rem;
}

.lens-compact.is-embed {
  width: auto;
  max-width: none;
  padding: 1rem;
}

.lens-compact.is-embed h1 {
  font-size: 1.45rem;
}

.lens-side {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.15rem 1.25rem;
}

.lens-side h1 {
  font-size: 1.7rem;
  margin-bottom: 0.35rem;
}

.lens-frame-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow);
  min-height: 70vh;
}

.lens-frame-placeholder {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 30% 20%, rgba(15, 110, 106, 0.08), transparent 40%),
    #f7f3ea;
  padding: 1.5rem;
}

.lens-placeholder-inner {
  text-align: center;
  max-width: 28rem;
  color: var(--muted);
  line-height: 1.5;
}

.lens-placeholder-inner p {
  margin: 0 0 0.75rem;
}

.lens-preview {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #dfe8e6;
  margin: 1rem 0;
  cursor: grab;
  border: 2px dashed rgba(15, 110, 106, 0.35);
}

.lens-preview:active {
  cursor: grabbing;
}

.lens-preview img {
  display: block;
  width: 100%;
  height: auto;
  -webkit-user-drag: element;
  user-select: none;
}

.lens-drag-hint {
  margin: 0;
  padding: 0.55rem 0.75rem;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(255, 252, 246, 0.92);
}

@media (max-width: 900px) {
  .lens-split {
    grid-template-columns: 1fr;
  }

  .lens-frame,
  .lens-frame-wrap {
    min-height: 55vh;
  }
}

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

@media (max-width: 820px) {
  .detail-layout,
  .form-grid,
  .catalog-hero {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: start;
  }

  .topbar {
    border-radius: 18px;
    flex-direction: column;
    align-items: start;
  }

  .stats-panels {
    grid-template-columns: 1fr;
  }
}

.stats-hero-value {
  margin: 0 0 1.25rem;
  padding: 1.4rem 1.3rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  animation: rise 0.45s ease both;
}

.stats-total {
  margin: 0.2rem 0 0.35rem;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--accent);
  line-height: 1;
}

.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stat-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.stat-value {
  margin: 0.35rem 0 0;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-card .hint {
  margin: 0.3rem 0 0;
  font-size: 0.8rem;
}

.stats-panels {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 1rem;
  align-items: start;
}

.stats-panel {
  padding: 1.15rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stats-panel h2 {
  font-size: 1.2rem;
  margin: 0 0 0.85rem;
}

.stats-subhead {
  margin-top: 1.4rem !important;
}

.stats-bars {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
  max-height: 28rem;
  overflow: auto;
}

.stats-bar-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.3rem;
  font-size: 0.92rem;
}

.stats-bar-meta span {
  color: var(--muted);
  white-space: nowrap;
}

.stats-bar-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(28, 42, 46, 0.1);
  overflow: hidden;
}

.stats-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.stats-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.stats-list li,
.stats-list-top a {
  display: grid;
  grid-template-columns: 1.2fr 0.7fr auto;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}

.stats-list-top a {
  width: 100%;
}

.stats-list-top a:hover strong {
  color: var(--accent);
}

.stats-price {
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.photo-search-form {
  margin-bottom: 1.5rem;
}

.photo-search-results {
  margin-top: 1.5rem;
}

.photo-search-results h2 {
  font-size: 1.25rem;
  margin: 0 0 0.85rem;
}

.photo-search-query {
  margin-bottom: 1.25rem;
  max-width: 280px;
}

.photo-search-query img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #dfe8e6;
  display: block;
}

.match-score {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
}

/* Gestione utenti */
.users-page .form-head {
  margin-bottom: 1.5rem;
}

.role-guide {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.75rem;
}

.role-card {
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg) 88%, #fff);
}

.role-card h2 {
  margin: 0 0 0.55rem;
  font-size: 1rem;
  font-family: inherit;
}

.role-card ul {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.role-card.role-admin {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
}

.users-panel {
  margin-bottom: 1.75rem;
}

.section-title {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.section-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: #e8eeec;
  color: #3a4a46;
}

.status-online {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 700;
  color: #2f9e44;
  font-size: 0.9rem;
}

.status-online::before {
  content: '';
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: #2f9e44;
}

.ip-addr {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.85rem;
  font-weight: 600;
  background: transparent;
}

.multi-ip-alert {
  margin-bottom: 1.25rem;
}

.multi-ip-alert ul {
  margin: 0.5rem 0 0;
  padding-left: 1.15rem;
}

.multi-ip-alert li {
  margin: 0.25rem 0;
}

.users-table tr.is-multi-ip {
  background: #fff8e8;
}

.multi-ip-tag {
  margin-top: 0.25rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: #8a5a00;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.ip-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.3rem;
}

.ip-list li {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: baseline;
}

.ip-list .ip-addr {
  display: inline-block;
  margin-right: 0.15rem;
}

.access-page .hint {
  margin-top: 0.65rem;
}

/* Cerca nei cataloghi PDF */
.catalog-search-form {
  margin-bottom: 0.75rem;
}

.inline-reindex {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin: 0.5rem 0 0.75rem;
}

.reindex-force {
  margin: 0;
}

.catalog-hit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.catalog-hit {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto 1fr;
}

.catalog-hit-preview {
  background: #dfe8e6;
  aspect-ratio: 3 / 4;
  overflow: hidden;
}

.catalog-hit-preview a {
  display: block;
  height: 100%;
}

.catalog-hit-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: top center;
  display: block;
  background: #fff;
}

.catalog-hit-placeholder {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}

.catalog-hit-body {
  padding: 0.85rem 1rem 1rem;
}

.catalog-hit-code {
  margin: 0.35rem 0 0;
  font-size: 0.92rem;
}

.catalog-hit-snippet {
  margin: 0.45rem 0 0;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--muted);
}

.detail-catalogs {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

.detail-catalogs-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.detail-catalogs-head h2 {
  margin: 0;
  font-size: 1.25rem;
}

.detail-catalogs-head .hint {
  margin: 0.25rem 0 0;
}

.detail-catalogs-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.detail-catalogs-actions .inline-photo-search {
  display: inline;
  margin: 0;
}

.catalog-query-preview {
  max-width: 220px;
  margin-bottom: 1rem;
}

.catalog-query-preview h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.catalog-query-preview img {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  display: block;
}

/* Visualizzatore pagina catalogo con zoom */
.catalog-viewer-page {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 2rem);
  gap: 0.6rem;
}

.catalog-viewer-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.35rem 0;
}

.catalog-viewer-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
}

.catalog-viewer-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.catalog-zoom-label {
  min-width: 3.5rem;
  text-align: center;
  font-weight: 700;
  color: var(--muted);
  font-size: 0.9rem;
}

.catalog-viewer-stage {
  flex: 1;
  min-height: 70vh;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(45deg, #e8eeec 25%, transparent 25%),
    linear-gradient(-45deg, #e8eeec 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e8eeec 75%),
    linear-gradient(-45deg, transparent 75%, #e8eeec 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-color: #dfe8e6;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  position: relative;
}

.catalog-viewer-stage.is-dragging {
  cursor: grabbing;
}

.catalog-viewer-canvas {
  position: absolute;
  top: 0;
  left: 0;
  will-change: transform;
}

.catalog-viewer-canvas img {
  display: block;
  max-width: none;
  user-select: none;
  -webkit-user-drag: none;
  box-shadow: 0 10px 30px rgba(28, 42, 46, 0.18);
  background: #fff;
}

.catalog-viewer-hint {
  margin: 0;
}

.users-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.users-table th,
.users-table td {
  padding: 0.75rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.users-table th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}

.users-table tr:last-child td {
  border-bottom: 0;
}

.users-table tr.is-editing {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.users-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-end;
}

.inline-form {
  display: inline;
  margin: 0;
}

.role-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: #e8eeec;
  color: #3a4a46;
}

.role-badge.role-admin {
  background: color-mix(in srgb, var(--accent) 18%, #fff);
  color: var(--accent);
}

.role-badge.role-editor {
  background: #e7eff8;
  color: #2c5282;
}

.role-badge.role-viewer {
  background: #eeeae4;
  color: #5c5346;
}

.tag-you {
  margin-left: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.users-form {
  max-width: 720px;
}

.users-form .form-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.muted {
  color: var(--muted);
}

.user-role-hint {
  font-size: 0.8rem;
  margin-top: 0.15rem;
}

.perm-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.perm-chip {
  display: inline-block;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #e8eeec;
  color: #3a4a46;
}

.perm-fieldset {
  margin: 1rem 0 0;
  padding: 0.9rem 1rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.perm-fieldset legend {
  padding: 0 0.35rem;
  font-weight: 700;
  font-size: 0.95rem;
}

.perm-check {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  margin: 0.45rem 0;
  font-weight: 500;
  cursor: pointer;
}

.perm-check input {
  margin-top: 0.2rem;
  width: auto;
}

@media (max-width: 700px) {
  .users-actions {
    justify-content: flex-start;
  }
}

/* —— Ricerca visiva (PDF) —— */
.visual-search-page {
  display: grid;
  gap: 1.25rem;
}

.visual-search-panel,
.visual-search-run {
  padding: 1.25rem 1.4rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.visual-search-form {
  display: grid;
  gap: 1rem;
  max-width: 40rem;
}

.visual-search-form .field {
  display: grid;
  gap: 0.35rem;
}

.visual-search-form .field > span {
  font-weight: 600;
  font-size: 0.92rem;
}

/* Desktop: CTA fotocamera telefono come field normale */
.vs-camera-field .vs-camera-cta {
  font-weight: 600;
  font-size: 0.92rem;
}

.vs-camera-field .vs-camera-input {
  width: 100%;
}

.vs-gallery-label-mobile {
  display: none;
}

.vs-start-btn {
  width: 100%;
  max-width: 40rem;
}

.visual-search-form input[type="text"],
.visual-search-form input[type="number"],
.visual-search-form input[type="file"] {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font: inherit;
}

.visual-search-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.checkbox-field {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  grid-template-columns: none !important;
}

.checkbox-field input {
  width: auto !important;
}

.visual-search-preview {
  max-width: 220px;
  display: grid;
  gap: 0.5rem;
}

.visual-search-preview img {
  display: block;
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.visual-search-preview .btn {
  justify-self: start;
}

.visual-search-preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.35rem;
}

.visual-search-preview-actions .btn {
  justify-self: stretch;
}

.vs-original-panel {
  margin-top: 0.65rem;
  padding: 0.55rem 0.65rem;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: rgba(255, 252, 246, 0.7);
}

.vs-original-panel[hidden] {
  display: none !important;
}

.vs-original-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  margin-top: 0.35rem;
}

.vs-original-row img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.lasso-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.88);
  overscroll-behavior: none;
  touch-action: none;
}

.lasso-overlay[hidden] {
  display: none !important;
}

.lasso-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  height: 100dvh;
  min-height: 0;
  color: #f4f7f8;
}

.lasso-toolbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.75rem;
  padding: max(0.55rem, env(safe-area-inset-top)) 0.75rem 0.55rem;
  background: rgba(16, 22, 26, 0.96);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.lasso-toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.lasso-toolbar .lasso-actions {
  margin-left: auto;
}

.lasso-title {
  font-weight: 650;
  font-size: 0.98rem;
  margin-right: 0.35rem;
}

.lasso-zoom-label {
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  opacity: 0.8;
  min-width: 3.2rem;
}

.lasso-toolbar .btn {
  color: #eef3f5;
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.06);
  min-height: 2.4rem;
  padding: 0.4rem 0.7rem;
}

.lasso-toolbar .btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #f7fffe;
}

.lasso-toolbar .btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #f7fffe;
}

.lasso-lab-ico {
  display: none;
}

.lasso-viewport {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  background:
    linear-gradient(45deg, #2a3238 25%, transparent 25%) 0 0 / 20px 20px,
    linear-gradient(-45deg, #2a3238 25%, transparent 25%) 0 0 / 20px 20px,
    #1a2126;
}

.lasso-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.lasso-canvas.is-pan,
.lasso-overlay.is-space-pan .lasso-canvas {
  cursor: grab;
}

.lasso-canvas.is-erase {
  cursor: cell;
}

.lasso-canvas.is-panning {
  cursor: grabbing !important;
}

.lasso-status {
  flex: 0 0 auto;
  margin: 0;
  padding: 0.45rem 0.85rem max(0.55rem, env(safe-area-inset-bottom));
  font-size: 0.86rem;
  color: rgba(244, 247, 248, 0.82);
  background: rgba(16, 22, 26, 0.96);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

@media (max-width: 720px) {
  .lasso-toolbar {
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.25rem 0.35rem;
    max-height: 50px;
    min-height: 48px;
    padding: max(0.3rem, env(safe-area-inset-top)) 0.4rem 0.3rem;
    overflow: hidden;
  }

  .lasso-toolbar-meta {
    display: none;
  }

  .lasso-lab-full {
    display: none;
  }

  .lasso-lab-ico {
    display: inline;
  }

  .lasso-tools {
    flex: 1 1 auto;
    flex-wrap: nowrap;
    gap: 0.2rem;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .lasso-tools::-webkit-scrollbar {
    display: none;
  }

  #vsLassoOne {
    display: none;
  }

  .lasso-toolbar .lasso-actions {
    margin-left: auto;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: 0.3rem;
  }

  .lasso-toolbar .btn {
    flex: 0 0 auto;
    min-width: 2.35rem;
    min-height: 2.35rem;
    padding: 0.25rem 0.4rem;
    font-size: 0.95rem;
    line-height: 1;
  }

  .lasso-toolbar .lasso-actions .btn-ghost {
    padding: 0.25rem 0.5rem;
    font-size: 0.78rem;
  }

  .lasso-toolbar .lasso-actions .btn-primary {
    flex: 0 0 auto;
    padding: 0.3rem 0.55rem;
    font-size: 0.78rem;
    font-weight: 650;
    white-space: nowrap;
  }

  .lasso-status {
    display: none;
  }
}

.visual-search-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.visual-search-assoc-form {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.45rem;
  align-items: center;
  margin: 0.65rem 0 0.75rem;
  max-width: 28rem;
}

.visual-search-assoc-form input[type="search"] {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.55rem 0.75rem;
  font: inherit;
  font-size: 16px;
  background: #fff;
}

.visual-search-assoc-form .btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.vs-assoc-list {
  display: grid;
  gap: 0.4rem;
  margin-top: 0.35rem;
}

.vs-assoc-row {
  display: grid;
  grid-template-columns: 3rem minmax(4.5rem, 7rem) minmax(0, 1fr) auto;
  gap: 0.55rem 0.65rem;
  align-items: center;
  width: 100%;
  margin: 0;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  appearance: none;
}

.vs-assoc-row:hover {
  border-color: rgba(15, 110, 106, 0.35);
}

.vs-assoc-row.is-source-selected {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.vs-assoc-thumb {
  width: 3rem;
  height: 3rem;
  border-radius: 8px;
  overflow: hidden;
  background: #dfe8e6;
  display: grid;
  place-items: center;
}

.vs-assoc-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.vs-assoc-code {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vs-assoc-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vs-assoc-row .btn-select-source {
  min-height: 2.2rem;
  padding: 0.35rem 0.7rem;
  font-size: 0.88rem;
}

.visual-match-card.is-source-selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visual-search-stats {
  flex: 1;
  min-width: 220px;
}

.stat-line {
  margin: 0 0 0.35rem;
  color: var(--muted);
}

.stat-line strong {
  color: var(--ink);
}

.visual-search-bar {
  margin-top: 0.6rem;
  height: 8px;
  border-radius: 999px;
  background: rgba(28, 42, 46, 0.08);
  overflow: hidden;
}

.visual-search-bar-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.25s ease;
}

.visual-search-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.visual-search-section {
  margin-top: 1.25rem;
}

.visual-search-section-title {
  font-size: 1rem;
  font-weight: 650;
  margin: 0 0 0.75rem;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.visual-search-section-title span {
  font-weight: 500;
  opacity: 0.65;
  font-size: 0.9em;
}

.visual-match-card--collection {
  outline: 1px solid color-mix(in srgb, currentColor 18%, transparent);
}

.visual-match-card--collection.is-source-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 110, 106, 0.22);
  outline: none;
}

.visual-match-card--collection .js-coll-source-mark {
  color: var(--accent);
  font-style: normal;
  font-size: 0.82rem;
}

#vsSourceHint {
  margin: 0.35rem 0 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  background: rgba(15, 110, 106, 0.08);
  border: 1px solid rgba(15, 110, 106, 0.22);
}

.visual-search-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.visual-match-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
}

.visual-match-card img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: var(--bg-deep);
}

.visual-match-meta {
  display: grid;
  gap: 0.15rem;
  padding: 0.65rem 0.75rem 0.8rem;
  font-size: 0.9rem;
}

.visual-match-meta span {
  color: var(--muted);
}

.visual-match-actions {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.45rem;
}

.visual-match-actions .btn {
  width: 100%;
  font-size: 0.85rem;
  padding: 0.45rem 0.6rem;
}

.visual-match-meta .btn-create-piece {
  font-weight: 600;
}

.catalog-hit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.65rem;
}

.catalog-select-box {
  position: absolute;
  border: 2px solid #1f7a3a;
  background: color-mix(in srgb, #1f7a3a 18%, transparent);
  pointer-events: none;
  box-sizing: border-box;
  z-index: 2;
}

.catalog-viewer-stage.select-mode,
.catalog-viewer-stage.is-selecting {
  cursor: crosshair;
}

.catalog-viewer-tools .btn.is-active {
  outline: 2px solid color-mix(in srgb, currentColor 35%, transparent);
  outline-offset: 1px;
}

.catalog-import-photo-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-start;
}

.catalog-import-preview {
  max-width: min(280px, 100%);
  border-radius: 12px;
  display: block;
  background: #fff;
  box-shadow: 0 6px 18px rgba(28, 42, 46, 0.12);
}

.catalog-import-candidates {
  display: grid;
  gap: 0.55rem;
}

.catalog-import-candidate {
  display: grid;
  grid-template-columns: auto 56px 1fr;
  gap: 0.65rem;
  align-items: center;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}

.catalog-import-candidate img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--bg-deep);
}

.catalog-import-no-photo {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  font-size: 0.7rem;
  text-align: center;
  color: var(--muted);
  background: var(--bg-deep);
  border-radius: 8px;
}

.catalog-import-candidate small {
  display: block;
  margin-top: 0.15rem;
}

.catalog-import-fill {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1rem;
  margin: 1rem 0;
  padding: 0.75rem 0;
  border: none;
  border-top: 1px solid var(--line);
}

.catalog-import-fill legend {
  padding: 0;
  font-weight: 600;
  margin-bottom: 0.35rem;
  width: 100%;
}

.catalog-import-candidate.is-source {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 110, 106, 0.18);
}

.catalog-import-candidate.is-active-sel:not(.is-source) {
  border-color: #3d6e8c;
  box-shadow: 0 0 0 2px rgba(61, 110, 140, 0.16);
}

.catalog-import-compare-photos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin: 0.75rem 0 1rem;
}

.catalog-import-compare-photos figure {
  margin: 0;
  padding: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.catalog-import-compare-photos figcaption {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.catalog-import-compare-photo-slot {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3f6f5;
  border-radius: 8px;
  overflow: hidden;
}

.catalog-import-compare-photo-slot img,
.catalog-import-compare-photos img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  background: #f3f6f5;
  border-radius: 8px;
}

.catalog-import-compare-table {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.catalog-import-compare-row {
  display: grid;
  grid-template-columns: 0.9fr 1.2fr 1.2fr auto;
  gap: 0.55rem;
  align-items: start;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}

.catalog-import-compare-row.is-head {
  background: transparent;
  border: none;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  padding-bottom: 0.15rem;
  cursor: default;
}

.catalog-import-compare-row.is-disabled {
  opacity: 0.55;
  cursor: default;
}

.catalog-import-compare-row .cmp-cur,
.catalog-import-compare-row .cmp-cat {
  font-size: 0.92rem;
  word-break: break-word;
}

/* Valori uguali attuale ↔ catalogo → verde (non cambiano) */
.catalog-import-compare-row.is-same {
  border-color: rgba(34, 140, 90, 0.35);
  background: rgba(34, 140, 90, 0.06);
}

.catalog-import-compare-row .cmp-cur.is-same-val,
.catalog-import-compare-row .cmp-cat.is-same-val {
  color: #1a7a4c;
  font-weight: 600;
}

/* Valori diversi → evidenzia il cambiamento */
.catalog-import-compare-row.is-diff {
  border-color: rgba(180, 110, 40, 0.35);
  background: rgba(180, 110, 40, 0.05);
}

.catalog-import-compare-row .cmp-cur.is-diff-val,
.catalog-import-compare-row .cmp-cat.is-diff-val {
  color: #8a4b12;
}

.catalog-import-compare-row .cmp-choice {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  font-size: 0.85rem;
}

.catalog-import-compare-row .cmp-choice-na {
  color: var(--muted);
  font-size: 0.85rem;
}

.catalog-import-compare-row .cmp-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: #f3f6f5;
}

.catalog-import-compare-row .cmp-toggle-btn {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0.28rem 0.7rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1.2;
}

.catalog-import-compare-row .cmp-toggle-btn.is-active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.catalog-import-compare-row.is-disabled .cmp-toggle-btn {
  cursor: default;
  opacity: 0.7;
}

.catalog-import-compare-row:not(.is-head):not(.is-disabled) {
  cursor: default;
}

@media (max-width: 800px) {
  .catalog-import-compare-row,
  .catalog-import-compare-row.is-head {
    grid-template-columns: 1fr;
  }
  .catalog-import-compare-photos {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .visual-search-row {
    grid-template-columns: 1fr;
  }
}

.status-dots-table {
  display: grid;
  gap: 0.25rem;
}

.status-dots-row {
  display: grid;
  grid-template-columns: 2rem 6.5rem 8rem 1fr;
  gap: 0.55rem;
  align-items: center;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  margin: 0;
  cursor: pointer;
}

.status-dots-row.is-head {
  background: transparent;
  border: none;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  cursor: default;
  padding-bottom: 0.15rem;
}

@media (max-width: 700px) {
  .status-dots-row,
  .status-dots-row.is-head {
    grid-template-columns: 2rem 5rem 1fr;
  }
  .status-dots-row span:last-child {
    grid-column: 2 / -1;
  }
}

/* ========== Mobile / smartphone ========== */
@media (max-width: 820px) {
  .page {
    width: min(1120px, calc(100% - 1rem));
    padding: 0.65rem 0 2.5rem;
    padding-bottom: max(2.5rem, env(safe-area-inset-bottom));
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    border-radius: 16px;
    padding: 0.65rem 0.75rem;
    gap: 0;
  }

  .topbar-main {
    width: 100%;
  }

  .nav-toggle {
    display: inline-flex;
  }

  .nav {
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: 100%;
    margin-top: 0.55rem;
    padding-top: 0.35rem;
    border-top: 1px solid var(--line);
  }

  .topbar.is-nav-open .nav {
    display: flex;
  }

  .nav a,
  .nav .nav-muted {
    display: block;
    padding: 0.7rem 0.35rem;
    border-bottom: 1px solid var(--line);
    font-size: 1rem;
  }

  .nav a:last-child,
  .nav .nav-muted:last-child {
    border-bottom: none;
  }

  h1 {
    font-size: clamp(1.55rem, 7vw, 2.1rem);
  }

  .search-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem 0.55rem;
    align-items: end;
  }

  .search-bar input[type="search"] {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    flex: none;
    min-height: 2.55rem;
    height: auto;
    padding: 0.65rem 0.85rem;
  }

  .sort-field {
    width: auto;
    min-width: 0;
  }

  .sort-field select {
    width: 100%;
    min-width: 0;
    padding: 0.55rem 0.45rem;
    font-size: 0.92rem;
  }

  .search-bar .btn,
  .search-bar .btn-ghost {
    width: 100%;
  }

  .catalog-hero {
    gap: 0.85rem;
  }

  .catalog-hero .btn {
    width: 100%;
    text-align: center;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75rem;
  }

  .view-switch {
    width: 100%;
  }

  .view-switch-btn {
    flex: 1 1 auto;
  }

  .item-list-head {
    display: none;
  }

  .item-row {
    grid-template-columns: 0.75rem 2.75rem minmax(0, 1fr);
    gap: 0.15rem 0.55rem;
    padding: 0.45rem 0.55rem;
    align-items: center;
  }

  .item-list.has-price .item-row {
    grid-template-columns: 0.75rem 2.75rem minmax(0, 1fr) auto;
  }

  .item-row .item-list-dot {
    grid-column: 1;
    grid-row: 1 / span 2;
  }

  .item-row .item-list-thumb {
    grid-column: 2;
    grid-row: 1 / span 2;
    width: 2.75rem;
    height: 2.75rem;
  }

  .item-row .item-list-code {
    grid-column: 3;
    grid-row: 1;
    font-size: 0.78rem;
  }

  .item-row .item-list-title {
    grid-column: 3;
    grid-row: 2;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 0.95rem;
    line-height: 1.25;
  }

  .item-row .item-list-price {
    grid-column: 4;
    grid-row: 1 / span 2;
    font-size: 0.88rem;
  }

  .actions,
  .lookup-links,
  .detail-catalogs-actions,
  .form-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .actions .btn,
  .lookup-links .btn,
  .detail-catalogs-actions .btn,
  .form-actions .btn {
    width: 100%;
    text-align: center;
  }

  .status-dot-picker {
    flex-wrap: wrap;
  }

  /* Crop / ritaglio: fullscreen, stage flessibile, toolbar sempre in schermo */
  .crop-modal {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
  }

  .crop-dialog {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
    padding: max(0.55rem, env(safe-area-inset-top)) 0.65rem max(0.65rem, env(safe-area-inset-bottom));
    margin: 0;
    min-height: 0;
  }

  .crop-dialog-head,
  .crop-aspects,
  .crop-toolbar {
    flex: 0 0 auto;
  }

  .crop-dialog-head h2 {
    font-size: 1.1rem;
  }

  .crop-dialog-head .hint {
    font-size: 0.82rem;
    margin: 0.25rem 0 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .crop-aspects {
    gap: 0.35rem;
    margin: 0.45rem 0 0;
  }

  .crop-aspects .btn,
  .crop-toolbar .btn {
    padding: 0.55rem 0.7rem;
    font-size: 0.88rem;
    min-height: 2.5rem;
  }

  .crop-stage {
    /* Riempie lo spazio rimanente: toolbar azioni resta sempre in vista */
    flex: 1 1 0;
    height: 0;
    min-height: 180px;
    max-height: none;
    margin: 0.35rem 0;
  }

  .crop-toolbar {
    gap: 0.45rem;
    max-height: none;
    overflow: visible;
    padding-bottom: max(0.25rem, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
  }

  .crop-toolbar-tools .btn {
    flex: 1 1 calc(50% - 0.4rem);
  }

  .crop-toolbar-actions {
    display: grid;
    grid-template-columns: 1fr 1.6fr;
    gap: 0.45rem;
  }

  .crop-toolbar-actions #vsCropCancel {
    grid-column: 1 / -1;
    order: 3;
  }

  .crop-toolbar-actions .btn-primary {
    grid-column: 2;
    width: 100%;
    min-width: 0;
    min-height: 3rem;
    font-size: 1.05rem;
  }

  .crop-toolbar-actions .btn-ghost {
    grid-column: 1;
  }

  /* Catalog viewer */
  .catalog-viewer-page {
    min-height: calc(100dvh - 1rem);
  }

  .catalog-viewer-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .catalog-viewer-tools {
    justify-content: flex-start;
  }

  .catalog-viewer-tools .btn {
    flex: 1 1 auto;
    min-height: 2.5rem;
  }

  .catalog-viewer-stage {
    min-height: 55dvh;
  }

  /* Visual search / import */
  .visual-search-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .visual-search-assoc-form {
    flex-wrap: wrap;
    max-width: 100%;
  }

  .visual-search-assoc-form input[type="search"] {
    flex: 1 1 10rem;
    max-width: calc(100% - 5.5rem);
  }

  .vs-assoc-row {
    grid-template-columns: 2.75rem minmax(0, 1fr) auto;
    gap: 0.15rem 0.5rem;
  }

  .vs-assoc-row .vs-assoc-thumb {
    grid-column: 1;
    grid-row: 1 / span 2;
    width: 2.75rem;
    height: 2.75rem;
  }

  .vs-assoc-row .vs-assoc-code {
    grid-column: 2;
    grid-row: 1;
    font-size: 0.78rem;
  }

  .vs-assoc-row .vs-assoc-title {
    grid-column: 2;
    grid-row: 2;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    font-size: 0.92rem;
    line-height: 1.25;
  }

  .vs-assoc-row .btn-select-source {
    grid-column: 3;
    grid-row: 1 / span 2;
  }

  .visual-search-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .visual-search-actions .btn {
    flex: 1 1 auto;
  }

  .visual-search-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .visual-match-actions {
    grid-template-columns: 1fr;
  }

  .catalog-import-photo-row {
    flex-direction: column;
  }

  .catalog-import-candidates {
    grid-template-columns: 1fr;
  }

  .catalog-import-compare-photos {
    grid-template-columns: 1fr;
  }

  .status-dots-toolbar {
    flex-direction: column;
    align-items: stretch !important;
  }

  .status-dots-toolbar .btn,
  .status-dots-toolbar select {
    width: 100%;
  }

  .btn {
    min-height: 2.55rem;
  }

  input,
  select,
  textarea {
    font-size: 16px; /* evita zoom iOS */
  }

  .auth-shell {
    min-height: calc(100dvh - 2rem);
    padding: 0.5rem 0;
  }

  .auth-panel {
    padding: 1.35rem 1.1rem;
  }

  .form-page .item-form,
  .form-page .inline-lookup,
  .visual-search-panel,
  .visual-search-run {
    padding: 1rem 0.9rem;
  }

  .photo-manage-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }

  .detail-info,
  .gallery {
    padding: 0.85rem;
  }

  .detail-catalogs-head {
    flex-direction: column;
    align-items: stretch;
  }

  .thumbs {
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.25rem;
  }

  .price-range {
    padding: 0.85rem 0.9rem;
  }

  .price-range-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }

  .users-table-wrap,
  .catalog-import-compare-table {
    -webkit-overflow-scrolling: touch;
  }

  .catalog-import-compare-row .cmp-toggle-btn {
    min-height: 2.4rem;
    padding: 0.45rem 0.55rem;
  }

  .visual-search-preview {
    max-width: 100%;
  }

  .visual-search-preview .btn {
    width: 100%;
    justify-self: stretch;
    text-align: center;
  }

  .filter-check {
    width: 100%;
    justify-content: flex-start;
  }
}

/* Visual search: mobile-first scatto / galleria / sticky Avvia */
@media (max-width: 768px) {
  #vsCameraBox {
    display: none !important;
  }

  .visual-search-form {
    max-width: none;
  }

  .vs-camera-field {
    order: -20;
    position: relative;
    margin: 0;
    padding: 0;
    border: none;
  }

  .vs-camera-field .vs-camera-desktop-hint,
  .vs-gallery-field .vs-gallery-desktop-hint {
    display: none;
  }

  .vs-camera-field .vs-camera-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    width: 100%;
    min-height: 48px;
    padding: 0.85rem 1rem;
    border-radius: 12px;
    background: var(--accent);
    color: #f7fffe;
    border: 1px solid var(--accent);
    font-weight: 700;
    font-size: 1.05rem;
    text-align: center;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .vs-camera-field .vs-camera-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    font-size: 0;
  }

  .vs-gallery-field {
    order: -19;
  }

  .vs-gallery-label-desktop {
    display: none;
  }

  .vs-gallery-label-mobile {
    display: inline;
  }

  .vs-gallery-field .vs-gallery-label {
    font-weight: 600;
    font-size: 0.92rem;
  }

  #vsPasteWrap {
    order: -18;
  }

  #vsPreviewWrap {
    order: -17;
  }

  /* Sticky «Avvia ricerca» quando c’è un’anteprima */
  body.vs-has-preview .vs-start-btn {
    position: sticky;
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 100;
    width: 100%;
    min-height: 3rem;
    margin-top: 0.75rem;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
  }

  body.vs-has-preview .visual-search-panel {
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
  }
}

@media (max-width: 480px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tile-body {
    padding: 0.65rem 0.7rem 0.85rem;
  }

  .tile-body h2 {
    font-size: 1rem;
  }

  .photo-manage-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .crop-aspects .btn {
    flex: 1 1 calc(50% - 0.35rem);
  }
}

