/* Grafica ripresa dal sito pubblico di Garzone: stessi colori, font e forme. */
@font-face { font-family: 'Inter'; font-weight: 400; font-display: swap; src: url('fonts/inter-latin-400.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 500; font-display: swap; src: url('fonts/inter-latin-500.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 600; font-display: swap; src: url('fonts/inter-latin-600.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 700; font-display: swap; src: url('fonts/inter-latin-700.woff2') format('woff2'); }

:root {
  --g-50: #EEF4ED;
  --g-200: #8DA9C4;
  --g-400: #4A79A6;
  --g-500: #134074;
  --g-600: #13315C;
  --g-700: #0B2545;
  --g-800: #091D36;
  --g-900: #061527;
  --blue: #2563EB;
  --blue-dark: #1D4ED8;
  --ink: #1E293B;
  --muted: #64748B;
  --line: #E2E8F0;
  --green: #4ADE80;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--g-700);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
:focus-visible { outline: 2px solid var(--g-500); outline-offset: 2px; }
.wrap { width: 100%; max-width: 1280px; margin: 0 auto; padding: 0 32px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Barra in alto */
.nav { position: relative; z-index: 5; height: 64px; background: #fff; border-bottom: 1px solid #F1F5F9; }
.nav-inner { height: 100%; display: flex; align-items: center; justify-content: space-between; }
body:has(#view-scan:not([hidden])) .nav-inner { max-width: 1680px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--g-700); color: var(--g-50); display: grid; place-items: center; font-weight: 700; font-size: 18px; }
.brand-name { color: var(--g-700); font-size: 20px; font-weight: 700; }
.brand-name span { color: var(--g-400); }
.nav-tag { font-size: 14px; font-weight: 500; color: #475569; }

/* Modulo */
.hero {
  min-height: calc(100vh - 64px);
  display: flex;
  align-items: center;
  background-color: var(--g-700);
  background-image: radial-gradient(rgba(255, 255, 255, .14) 1px, transparent 1px);
  background-size: 40px 40px;
}
.hero-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 64px; align-items: center; padding-top: 56px; padding-bottom: 56px; }
.hero h1 { margin: 0 0 24px; color: #fff; font-size: clamp(32px, 4.4vw, 60px); line-height: 1.12; font-weight: 700; letter-spacing: -.01em; }
.hero h1 span { color: var(--g-200); }
.hero p { margin: 0 0 32px; max-width: 34em; color: var(--g-200); font-size: 19px; line-height: 1.6; }

.card { background: #fff; border: 1px solid var(--line); border-radius: 16px; }
.form { padding: 32px; box-shadow: 0 24px 60px -24px rgba(6, 21, 39, .8); }
.field { margin-bottom: 20px; min-width: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 500; color: #334155; }
.field em { font-style: normal; font-weight: 400; color: #94A3B8; margin-left: 4px; }
.field input, .field textarea {
  width: 100%;
  padding: 10px 16px;
  border: 1px solid #CBD5E1;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; line-height: 1.5; }
.field input[readonly], .field textarea[readonly] { background: #F8FAFC; color: #334155; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--g-500); box-shadow: 0 0 0 2px rgba(19, 64, 116, .35); }
.mono-input { font-family: var(--mono) !important; letter-spacing: .04em; text-transform: uppercase; }
.mono-input::placeholder { text-transform: none; letter-spacing: 0; font-family: 'Inter', sans-serif; }
.form-error { margin: 0 0 16px; padding: 10px 14px; border-radius: 8px; background: #FEF2F2; border: 1px solid #FECACA; color: #B91C1C; font-size: 14px; line-height: 1.45; }

.btn-primary, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 32px; border-radius: 8px; font: inherit; font-size: 16px; font-weight: 600; cursor: pointer; transition: background .15s, opacity .15s;
}
.btn-primary { border: 0; background: var(--blue); color: #fff; box-shadow: 0 10px 20px -8px rgba(37, 99, 235, .5); }
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.btn-primary svg, .btn-ghost svg { width: 20px; height: 20px; flex: none; }
#job-form .btn-primary { width: 100%; }
.btn-ghost { background: transparent; color: var(--g-200); border: 1px solid rgba(141, 169, 196, .3); }
.btn-ghost:hover { background: rgba(255, 255, 255, .05); }
.btn-ghost:focus-visible { outline-color: #fff; }

/* Scansione */
.stage {
  position: relative;
  height: calc(100vh - 64px);
  min-height: 640px;
  overflow: hidden;
  background: radial-gradient(ellipse 70% 70% at 42% 48%, var(--g-600) 0%, var(--g-700) 48%, var(--g-900) 100%);
  animation: stage-in .7s ease-out both;
}
@keyframes stage-in { from { opacity: 0; } to { opacity: 1; } }
.stage-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage-layout {
  position: relative;
  max-width: 1680px;
  height: 100%;
  padding-top: 24px;
  padding-bottom: 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "head head" "space feed" "hud hud";
  gap: 16px 24px;
  pointer-events: none;
}
.stage-head { grid-area: head; display: flex; justify-content: space-between; align-items: center; gap: 16px; color: var(--g-200); font-size: 14px; }
.live { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 500; min-width: 0; }
.live i { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 0 rgba(74, 222, 128, .6); animation: live 1.6s infinite; }
@keyframes live { 70% { box-shadow: 0 0 0 10px rgba(74, 222, 128, 0); } 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); } }
.stage-meta { display: flex; gap: 20px; white-space: nowrap; }
.stage-spacer { grid-area: space; }

.glass { background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .1); border-radius: 16px; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.feed-panel { grid-area: feed; align-self: center; padding: 18px 20px; min-height: 0; max-height: 100%; overflow-y: auto; pointer-events: auto; }
.feed-panel h2 { margin: 0 0 12px; color: rgba(255, 255, 255, .5); font-size: 12px; font-weight: 500; }
.feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; min-height: 20px; }
.feed li { display: flex; gap: 10px; color: rgba(255, 255, 255, .55); font-size: 13px; line-height: 1.4; animation: feed-in .35s ease-out both; overflow-wrap: anywhere; }
.feed li::before { content: ''; flex: none; width: 6px; height: 6px; margin-top: 6px; border-radius: 50%; background: var(--g-200); opacity: .5; }
.feed li:last-child { color: #fff; }
.feed li:last-child::before { background: #60A5FA; opacity: 1; box-shadow: 0 0 8px #60A5FA; }
.feed li.ok::before { background: var(--green); opacity: 1; box-shadow: none; }
@keyframes feed-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.hud { grid-area: hud; display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "part code"; gap: 14px 32px; align-items: end; }
.hud-part { grid-area: part; min-width: 0; }
.hud-label { display: block; margin-bottom: 4px; color: var(--g-200); font-size: 14px; }
.hud-part strong { display: block; color: #fff; font-size: clamp(22px, 2.6vw, 34px); font-weight: 700; line-height: 1.15; overflow-wrap: anywhere; }

.code-slot { grid-area: code; display: flex; gap: 3px; min-height: 54px; }
.code-slot .ch {
  width: 28px; height: 54px; border-radius: 6px; display: grid; place-items: center;
  background: rgba(6, 21, 39, .72); border: 1px solid rgba(141, 169, 196, .22);
  color: #93C5FD; font: 600 22px var(--mono);
  transition: color .2s, border-color .2s, background .2s, transform .25s;
}
.code-slot .ch.gap { width: 10px; background: none; border: 0; }
.code-slot .ch.locked { color: #fff; background: rgba(34, 197, 94, .2); border-color: rgba(74, 222, 128, .7); transform: translateY(-2px); }
.code-slot.empty .ch { color: rgba(141, 169, 196, .55); }

/* Risultati che compaiono durante la ricerca */
.live-parts { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 10px; }
.live-part { padding: 10px 12px; border-radius: 10px; background: rgba(6, 21, 39, .45); border: 1px solid rgba(255, 255, 255, .08); transition: border-color .3s, background .3s; }
.live-name { display: block; margin-bottom: 7px; color: var(--g-200); font-size: 12px; font-weight: 500; overflow-wrap: anywhere; }
.live-body { display: grid; gap: 7px; }
.live-skeleton { position: relative; display: block; height: 10px; border-radius: 5px; overflow: hidden; background: rgba(141, 169, 196, .16); }
.live-skeleton-code { width: 62%; height: 14px; }
.live-skeleton-text { width: 88%; }
.live-skeleton::after { content: ''; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(191, 219, 254, .42), transparent); animation: live-shimmer 1.5s ease-in-out infinite; }
.live-part.active { border-color: rgba(96, 165, 250, .6); background: rgba(19, 64, 116, .5); }
.live-part.active .live-name { color: #fff; }
.live-part.active .live-skeleton::after { animation-duration: .95s; }
@keyframes live-shimmer { to { transform: translateX(100%); } }
.live-part.ok { border-color: rgba(74, 222, 128, .45); background: rgba(34, 197, 94, .12); }
.live-part.ko { border-color: rgba(251, 191, 36, .35); background: rgba(245, 158, 11, .1); }
.live-piece { display: grid; gap: 2px; animation: feed-in .4s ease-out both; }
.live-code { color: #fff; font: 600 15px var(--mono); overflow-wrap: anywhere; }
.live-desc { color: rgba(255, 255, 255, .62); font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; }
.live-part.ko .live-desc { color: #FDE68A; }

/* Risultati */
.results { min-height: calc(100vh - 64px); padding: 48px 0 80px; background: var(--g-50); animation: results-in .5s ease-out both; }
@keyframes results-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.results-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.results-eyebrow { margin: 0 0 6px; color: var(--g-400); font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
.results-head h2 { margin: 0; color: var(--g-700); font-size: clamp(26px, 3vw, 36px); font-weight: 700; }
.results-meta { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.results-head .btn-primary { flex: none; }
.notice { margin: 0 0 20px; padding: 12px 16px; border-radius: 8px; font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.notice-demo { background: #FFFBEB; border: 1px solid #FDE68A; color: #92400E; }
.notice-error { background: #FEF2F2; border: 1px solid #FECACA; color: #B91C1C; }
.results-list { display: grid; gap: 16px; }
.part-card { padding: 24px; animation: card-in .45s ease-out both; }
@keyframes card-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.part-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.part-top h3 { margin: 0; color: var(--g-700); font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
.part-sub { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.badge { flex: none; display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; border: 1px solid; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-ok { background: #DCFCE7; color: #15803D; border-color: #BBF7D0; }
.badge-warn { background: #FEF3C7; color: #B45309; border-color: #FDE68A; }
.badge-bad { background: #FEE2E2; color: #B91C1C; border-color: #FECACA; }
.badge-off { background: var(--g-50); color: var(--g-500); border-color: var(--g-200); }
.piece { display: grid; grid-template-columns: minmax(170px, 230px) minmax(0, 1fr) auto; gap: 8px 24px; align-items: start; margin-top: 16px; padding-top: 16px; border-top: 1px solid #F1F5F9; }
.piece-code { color: var(--g-700); font: 600 18px var(--mono); overflow-wrap: anywhere; }
.piece-name { margin: 0; color: var(--ink); font-size: 14px; font-weight: 500; line-height: 1.45; overflow-wrap: anywhere; }
.piece-note { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.piece-facts { display: flex; gap: 20px; margin: 0; }
.piece-facts div { min-width: 40px; }
.piece-facts dt { color: #94A3B8; font-size: 12px; }
.piece-facts dd { margin: 2px 0 0; color: var(--ink); font-size: 14px; font-weight: 500; white-space: nowrap; }
.piece-flags { grid-column: 2 / -1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.piece-reason { grid-column: 2 / -1; margin: 0; color: #92400E; font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }

@media (max-width: 960px) {
  .wrap { padding: 0 16px; }
  .hero-grid { grid-template-columns: minmax(0, 1fr); gap: 32px; padding-top: 40px; padding-bottom: 40px; }
  .hero h1, .hero p { text-align: center; }
  .hero p { margin-left: auto; margin-right: auto; font-size: 17px; }
  .hero-copy { display: flex; flex-direction: column; align-items: center; }
  .form { padding: 20px; }
  .stage { height: auto; min-height: calc(100vh - 64px); }
  .stage-layout {
    min-height: calc(100vh - 64px);
    padding-top: 16px; padding-bottom: 16px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(400px, 1fr) auto auto;
    grid-template-areas: "head" "space" "hud" "feed";
  }
  .feed-panel { align-self: stretch; padding: 14px 16px; }
  .stage-head { font-size: 13px; }
  #scan-vehicle { display: none; }
  .hud { grid-template-columns: minmax(0, 1fr); grid-template-areas: "part" "code"; }
  .code-slot { min-height: 42px; justify-content: flex-start; flex-wrap: nowrap; overflow: hidden; }
  .code-slot .ch { flex: 1 1 0; width: auto; min-width: 0; max-width: 24px; height: 42px; font-size: 16px; }
  .code-slot .ch.gap { flex: 0 0 6px; width: 6px; }
  .results { padding-top: 32px; }
  .results-head { flex-direction: column; align-items: stretch; }
  .part-card { padding: 18px; }
  .piece { grid-template-columns: minmax(0, 1fr); }
  .piece-flags, .piece-reason { grid-column: 1; }
}
@media (max-width: 420px) {
  .field-row { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .btn-ghost, .btn-primary { padding-left: 20px; padding-right: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Tavola esplosa */
.btn-explode { padding: 5px 12px; border: 1px solid var(--g-700); border-radius: 999px; background: #fff; color: var(--g-700); font: 600 13px var(--sans, inherit); cursor: pointer; transition: background .15s, color .15s; }
.btn-explode:hover:not(:disabled) { background: var(--g-700); color: #fff; }
.btn-explode:disabled { opacity: .6; cursor: progress; }
.exploded { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px 20px; margin-top: 12px; padding: 16px; border: 1px solid #E2E8F0; border-radius: 12px; background: #F8FAFC; animation: feed-in .3s ease-out both; }
.exploded-title { grid-column: 1 / -1; margin: 0; color: var(--g-700); font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.exploded-drawing { position: relative; min-width: 0; }
.exploded-frame { height: 560px; overflow: auto; border: 1px solid #E2E8F0; border-radius: 8px; background: #fff; }
.exploded-frame img { display: block; height: 100%; width: auto; max-width: none; margin: 0 auto; }
.exploded-zoom { position: absolute; top: 8px; right: 8px; z-index: 1; display: flex; gap: 4px; }
.exploded-zoom-btn { width: 32px; height: 32px; border: 1px solid #CBD5E1; border-radius: 8px; background: #fff; color: var(--g-700); font-size: 18px; font-weight: 600; cursor: pointer; }
.exploded-empty, .exploded-error { margin: 0; color: var(--muted); font-size: 14px; }
.exploded-error { grid-column: 1 / -1; margin-top: 12px; color: #92400E; }
.exploded-list { max-height: 560px; min-width: 0; overflow: auto; border: 1px solid #E2E8F0; border-radius: 8px; background: #fff; }
.exploded-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.exploded-table th { position: sticky; top: 0; z-index: 1; padding: 8px; background: #F1F5F9; color: #64748B; font-weight: 600; text-align: left; }
.exploded-table td { padding: 7px 8px; border-top: 1px solid #F1F5F9; color: var(--ink); vertical-align: top; overflow-wrap: anywhere; }
.exploded-table small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.exploded-pos { font-weight: 600; white-space: nowrap; }
.exploded-code { font-family: var(--mono); white-space: nowrap; }
.exploded-table tr.hit td { background: #DCFCE7; font-weight: 600; }
.exploded-table tr.off td, .exploded-table tr.off small { color: #A3AEBD; }
.exploded-section td { background: #F8FAFC; color: var(--g-700); font-weight: 600; }
.exploded-legend { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 12px; }
.part-tables { display: grid; gap: 12px; margin-top: 16px; }
.part-table { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.part-table-name { flex: 1 1 200px; color: var(--ink); font-size: 14px; overflow-wrap: anywhere; }
.part-table .exploded { flex-basis: 100%; }
@media (max-width: 760px) {
  .exploded { grid-template-columns: minmax(0, 1fr); padding: 12px; }
  .exploded-frame { height: 420px; }
  .exploded-list { max-height: 420px; }
  .exploded-code { white-space: normal; }
}
