:root {
  --bg: #14161a;
  --surface: #1d2026;
  --surface-2: #262a32;
  --line: #2f343d;
  --text: #eceef2;
  --muted: #9aa1ad;
  --accent: #ff3b30;
  --accent-ink: #fff;
  --ok: #34c759;
  --warn: #ffb020;
  --changed: #ffb020;
  --radius: 12px;
  --nav-h: 58px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f4f6; --surface: #fff; --surface-2: #eceef2; --line: #d9dce2;
    --text: #15171b; --muted: #5d6573; --changed: #b36b00; color-scheme: light;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  background: var(--accent); color: var(--accent-ink); font-weight: 900; font-style: italic;
  padding: 4px 8px; border-radius: 6px; letter-spacing: .5px;
}
.titles { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; line-height: 1.15; }
.chip {
  background: none; border: 0; padding: 0; color: var(--muted); font-size: 13px;
  max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.top-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); font-size: 20px; }
.btn {
  border: 1px solid var(--line); background: var(--surface-2); padding: 9px 14px; border-radius: 10px; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--accent); }
.btn.small { padding: 6px 10px; font-size: 14px; }
.top .btn { white-space: nowrap; }
.btn:disabled { opacity: .5; }

/* Layout */
main { flex: 1; min-height: 0; position: relative; }
.view { display: none; height: 100%; overflow-y: auto; padding: 12px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
.view.active { display: block; }
#view-chat.active { display: flex; flex-direction: column; padding-bottom: 0; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; height: var(--nav-h); border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 12px; gap: 2px;
}
.tabs button span { font-size: 20px; line-height: 1; }
.tabs button.active { color: var(--text); box-shadow: inset 0 -3px 0 var(--accent); }

/* Setup */
.search {
  width: 100%; padding: 11px 14px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); margin-bottom: 12px;
}
details.sec { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
details.sec > summary {
  list-style: none; padding: 14px 16px; font-weight: 700; display: flex; align-items: center; gap: 10px; cursor: pointer;
}
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary .count { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--changed); }
details.sec > summary::after { content: "›"; color: var(--muted); font-size: 22px; transition: transform .15s; margin-left: 6px; }
details.sec[open] > summary::after { transform: rotate(90deg); }
.rows { border-top: 1px solid var(--line); }
.row { padding: 12px 16px; border-bottom: 1px solid var(--line); position: relative; }
.row:last-child { border-bottom: 0; }
.row.changed { box-shadow: inset 3px 0 0 var(--changed); }
.row .lab { display: flex; align-items: baseline; gap: 8px; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.row .lab .warn { color: var(--warn); border: 0; background: none; padding: 0 2px; font-size: 15px; }
.row .lab .extra { font-size: 11px; border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; }
.row .was { font-size: 12px; color: var(--changed); margin-top: 4px; }
.row .hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.row.hide { display: none; }
.pair-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pair-cols .col > small { display: block; color: var(--muted); font-size: 11px; margin-bottom: 4px; letter-spacing: .6px; }

input[type="text"], input[type="date"], input[type="password"], textarea, select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); min-height: 44px;
}
textarea { resize: vertical; }
.stepper { display: flex; align-items: stretch; gap: 6px; }
.stepper input { text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; min-width: 0; }
.stepper .unit { align-self: center; color: var(--muted); font-size: 13px; min-width: 2ch; }
.stepper button { width: 46px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); font-size: 22px; line-height: 1; flex: none; }
.stepper button:active { background: var(--line); }
.pair-cols .col { min-width: 0; }
.pair-cols .stepper { gap: 4px; }
.pair-cols .stepper .unit { display: none; }
.pair-cols .stepper button { width: 34px; }
.pair-cols .stepper input { padding: 10px 2px; }
.segs { display: flex; flex-wrap: wrap; gap: 6px; }
.segs button {
  flex: 1 1 auto; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text);
}
.segs button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.segs.multi button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.computed { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.computed small { font-size: 12px; font-weight: 400; color: var(--muted); display: block; }

/* Versioni */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.card h3 { margin: 0 0 2px; font-size: 16px; }
.card .meta { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.card .note { font-size: 14px; margin: 6px 0; white-space: pre-wrap; }
.card .acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.badge.cur { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }
.diff { width: 100%; border-collapse: collapse; font-size: 14px; }
.diff td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.diff td:first-child { color: var(--muted); }
.diff .to { color: var(--changed); font-weight: 700; }
.diff .from { text-decoration: line-through; color: var(--muted); }

/* Chat */
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 0 12px; }
.msg { max-width: 92%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.sys { align-self: center; color: var(--muted); font-size: 13px; text-align: center; }
.msg.err { align-self: stretch; border: 1px solid var(--accent); color: var(--accent); background: transparent; font-size: 14px; }
.msg b { font-weight: 700; }
.proposal { align-self: stretch; background: var(--surface); border: 1px solid var(--changed); border-radius: var(--radius); padding: 12px 14px; }
.proposal h4 { margin: 0 0 6px; font-size: 14px; color: var(--changed); }
.prop-item { padding: 8px 0; border-top: 1px solid var(--line); }
.prop-item:first-of-type { border-top: 0; }
.prop-item .what { font-weight: 700; }
.prop-item .why { font-size: 13px; color: var(--muted); margin: 2px 0 6px; }
.prop-item .state { font-size: 12px; color: var(--ok); }
.prop-item .state.no { color: var(--muted); }
.prop-item .state.bad { color: var(--accent); }
.prop-acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.quick { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.quick button { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 7px 12px; font-size: 13px; color: var(--muted); }
.composer {
  display: flex; gap: 8px; align-items: flex-end; padding: 8px 0 calc(var(--nav-h) + 10px + env(safe-area-inset-bottom));
  background: var(--bg);
}
.composer textarea { min-height: 46px; max-height: 120px; }
.modebar { margin-bottom: 10px; flex: none; flex-wrap: nowrap; }
.modebar button { font-size: 13px; min-height: 40px; padding: 6px 8px; }
#chat-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#chat-body.manual { overflow-y: auto; display: block; padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
.steps { margin: 6px 0 4px; padding-left: 20px; font-size: 14px; }
.steps li { margin-bottom: 4px; }
.sec-title { font-size: 14px; color: var(--muted); margin: 14px 2px 8px; font-weight: 600; }
#chat-body.manual .proposal { margin-bottom: 10px; }
#chat-body .hint { font-size: 12px; color: var(--muted); margin-top: 8px; }
.typing { align-self: flex-start; color: var(--muted); font-size: 13px; padding-left: 6px; }

/* Dialog + toast */
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); width: min(92vw, 520px); max-height: 86vh; padding: 18px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
dialog .acts { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
dialog p.small { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: .2s; z-index: 20; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
[hidden] { display: none !important; }

/* Mappe interattive: disegni originali + punti toccabili */
.map { display: flex; flex-direction: column; gap: 6px; }
.mapimg { position: relative; width: 100%; max-width: 520px; margin: 0 auto; background: #f3f5f8; border-radius: 8px; overflow: hidden; user-select: none; -webkit-user-select: none; }
.mapimg .art { pointer-events: none; }
.hs { position: absolute; padding: 0; margin: 0; border: 0; background: transparent; touch-action: manipulation; }
.hs::after { content: ""; position: absolute; inset: -9px; } /* area di tocco più grande del quadratino */
.hs::before { content: ""; position: absolute; inset: 0; border-radius: 2px; opacity: 0; transition: opacity .1s; }
.hs.dot::before { border-radius: 50%; inset: -6%; }
.hs.on::before { opacity: 1; background: #e53126; }
.hs.box.on::before { background: linear-gradient(45deg, transparent 43%, #e53126 43%, #e53126 57%, transparent 57%), linear-gradient(-45deg, transparent 43%, #e53126 43%, #e53126 57%, transparent 57%); box-shadow: none; inset: 0; }
.hs.slot.on::before { inset: 0; border-radius: 1px; }
.hs.chg::before { opacity: 1; box-shadow: 0 0 0 2px #ff9f0a; }
.hs.chg:not(.on)::before { background: transparent; box-shadow: none; border: 2.5px dashed #ff9f0a; }
.hs.box.chg.on::before { box-shadow: none; outline: 2.5px solid #ff9f0a; outline-offset: 1px; }
.hs .n { display: none; position: absolute; left: 50%; top: -4px; transform: translate(-50%, -100%); font: 700 11px/1 system-ui, sans-serif; color: #fff; background: #4a5568; border-radius: 8px; padding: 2px 5px; pointer-events: none; white-space: nowrap; }
.map.nums .hs .n { display: block; }
.map.nums .hs.on .n { background: #e53126; }
.maphint { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.numtog { flex: none; font-size: 12px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 4px 10px; color: var(--muted); }
.numtog.on { color: var(--text); border-color: var(--muted); }
.mapscroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 8px; background: #f3f5f8; }
.mapscroll .mapimg { max-width: none; margin: 0; border-radius: 0; }

/* locator: where the part sits on the car (original drawing) */
.loc { margin: 2px 0 10px; }
.loc .car { display: block; width: 100%; max-width: 420px; margin: 0 auto; border-radius: 10px; background: #f3f5f8; }
.loclab { display: block; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.artbox, .artbox .art { display: block; width: 100%; height: 100%; }

/* Parts */
.p-tabs { flex-wrap: nowrap; margin-bottom: 10px; }
.p-tabs button { flex: 1 1 auto; padding-left: 6px; padding-right: 6px; font-size: 14px; white-space: nowrap; }
.p-filters { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.p-filters select { flex: 1; min-width: 0; }
dialog label.p-kit, .p-kit { display: flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 14px; }
.card.p-row { display: flex; gap: 12px; padding: 10px; }
.p-thumb { flex: none; width: 76px; height: 76px; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); overflow: hidden; display: grid; place-items: center; }
.p-crop, .p-big { display: block; position: relative; width: 100%; background-color: #fff; background-repeat: no-repeat; }
.p-big { border-radius: 10px; border: 1px solid var(--line); overflow: hidden; }
.p-mark { position: absolute; border: 2px solid var(--accent); border-radius: 4px; }
.p-crop .p-mark { border-width: 1.5px; }
.p-ico { display: block; width: 48px; height: 48px; color: var(--muted); }
.p-ico svg { width: 100%; height: 100%; }
.p-noimg { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 0; }
.p-body { flex: 1; min-width: 0; }
.p-name { background: none; border: 0; padding: 0; text-align: left; font-weight: 600; font-size: 14px; line-height: 1.25; overflow-wrap: anywhere; }
.p-body .meta { margin: 4px 0 0; }
.p-body .meta .badge { margin-left: 6px; }
.card .p-body .acts { margin-top: 8px; align-items: center; }
.p-body .acts a.btn, dialog .acts a.btn { text-decoration: none; color: var(--text); }
.p-status { display: block; font-size: 12px; color: var(--ok); margin-top: 4px; }
.p-status:empty { display: none; }
.p-step { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; }
.p-step .btn { min-width: 36px; }
.p-cat { margin: 14px 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.acts.p-foot { display: flex; justify-content: center; margin: 12px 0 4px; }

