/* ===========================================================================
   §33 — Design system "Banco chiaro".
   Il pannello ricorda la scheda di centratura stampata. Il mirino resta scuro.
   Leggibile con una vetrina luminosa alle spalle: contrasti alti, niente vetro.
   =========================================================================== */

:root {
  --primary: #0d3b66;
  --primary-dark: #082a4a;
  --primary-tint: #e8eff6;
  --ink: #16202b;
  --ink-soft: #5a6875;
  --paper: #ffffff;
  --bench: #eef1f4;
  --rule: #c9d2da;
  --rule-strong: #9dabb8;
  --ok: #1f7a45;
  --warn: #9a6100;
  --danger: #9b2226;
  --danger-dark: #6d1518;

  --radius: 10px;
  --plinth: 3px;              /* §33 zoccolo dei pulsanti */
  --shadow-card: 0 1px 0 var(--rule), 0 2px 8px rgba(13, 59, 102, 0.06);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bench);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
code, pre { font-family: var(--mono); }
.muted { color: var(--ink-soft); }
[hidden] { display: none !important; }

/* ───────────────────────── Pulsanti con zoccolo ───────────────────────── */

.btn {
  appearance: none;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: 0 var(--plinth) 0 var(--primary-dark);
  transform: translateY(0);
  transition: transform 60ms linear, box-shadow 60ms linear, background 120ms;
  touch-action: manipulation;
  min-height: 44px;
}
.btn:active:not(:disabled) {
  transform: translateY(var(--plinth));
  box-shadow: 0 0 0 var(--primary-dark);
}
.btn:disabled { opacity: 0.45; cursor: default; box-shadow: 0 var(--plinth) 0 var(--rule-strong); }
.btn:focus-visible { outline: 3px solid #ffb703; outline-offset: 2px; }

.btn--primary { background: var(--primary); }
.btn--ghost {
  background: var(--paper);
  color: var(--primary);
  border-color: var(--rule-strong);
  box-shadow: 0 var(--plinth) 0 var(--rule-strong);
}
.btn--ghost:active:not(:disabled) { box-shadow: 0 0 0 var(--rule-strong); }
.btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  box-shadow: 0 var(--plinth) 0 var(--danger-dark);
}
.btn--danger:active:not(:disabled) { box-shadow: 0 0 0 var(--danger-dark); }
.btn--sm { padding: 7px 12px; font-size: 14px; min-height: 36px; }
.btn--dark {
  background: rgba(255,255,255,0.08);
  color: #f2f6fa;
  border-color: rgba(255,255,255,0.28);
  box-shadow: 0 var(--plinth) 0 rgba(0,0,0,0.5);
}

/* ───────────────────────── Banco ───────────────────────── */

.bench { max-width: 940px; margin: 0 auto; padding: 0 16px 48px; }

.bench__header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 0; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(var(--bench) 78%, rgba(238,241,244,0));
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--primary); }
.brand__mark { width: 32px; height: 32px; flex: none; }
.brand h1 { font-size: 20px; color: var(--primary); }
.brand__sub { margin: 0; font-size: 12px; color: var(--ink-soft); }
.header__actions { display: flex; gap: 8px; }

.bench__main { display: grid; gap: 16px; }

.card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 16px;
}
.card__title {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--primary); margin-bottom: 12px;
  padding-bottom: 8px; border-bottom: 2px solid var(--primary-tint);
}

.bench__footer { margin-top: 24px; font-size: 12px; color: var(--ink-soft); text-align: center; }

/* ───────────────────────── Alert ───────────────────────── */

.alert {
  border-radius: var(--radius); padding: 12px 14px; margin: 8px 0;
  border: 1px solid; font-size: 14px;
}
.alert--error { background: #fdeeee; border-color: #e0b4b5; color: var(--danger); }
.alert--warn  { background: #fff6e5; border-color: #e6cf9e; color: var(--warn); }
.alert--ok    { background: #eaf6ef; border-color: #a9d4bc; color: var(--ok); }

/* ───────────────────────── §27 Procedura ───────────────────────── */

.protocol {
  display: grid; gap: 8px; margin-bottom: 14px;
  padding: 12px; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--primary-tint);
}
.protocol__label {
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--primary); font-weight: 700;
}
.protocol__opts { display: flex; gap: 6px; flex-wrap: wrap; }
.protocol__btn {
  flex: 1 1 auto; min-width: 96px; min-height: 40px;
  border: 1px solid var(--rule-strong); border-radius: 8px;
  background: #fff; color: var(--primary); font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; padding: 8px 10px;
  box-shadow: 0 2px 0 var(--rule-strong);
}
.protocol__btn[aria-checked="true"] {
  background: var(--primary); color: #fff; border-color: var(--primary);
  box-shadow: 0 2px 0 var(--primary-dark);
}
.protocol__btn:active { transform: translateY(2px); box-shadow: none; }
.protocol__desc { margin: 0; font-size: 12.5px; color: var(--ink-soft); }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.step {
  border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 12px; display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between;
  background: #fcfdfe;
}
.step[data-state="done"] { border-color: #a9d4bc; background: #f4fbf7; }
.step[data-state="skipped"] { border-color: var(--rule); opacity: 0.72; }
.step__head { display: flex; gap: 12px; align-items: flex-start; min-width: 240px; flex: 1; }
.step__index {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
}
.step[data-state="done"] .step__index { background: var(--ok); }
.step__title { font-size: 15px; }
.step__meta { margin: 2px 0 0; font-size: 13px; color: var(--ink-soft); }
.step__actions { display: flex; gap: 8px; align-items: center; }

/* ───────────────────────── Risultati ───────────────────────── */

.results { display: grid; gap: 14px; }
.res-section h4 {
  margin: 0 0 6px; font-size: 12px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--primary);
}
table.res { width: 100%; border-collapse: collapse; font-size: 14px; }
table.res th, table.res td {
  border-bottom: 1px solid var(--rule); padding: 7px 8px; text-align: right;
  font-variant-numeric: tabular-nums;
}
table.res th:first-child, table.res td:first-child { text-align: left; font-weight: 500; }
table.res thead th { color: var(--ink-soft); font-size: 12px; text-transform: uppercase; }
table.res tr.full td { text-align: left; }
table.res td.val { font-weight: 650; }
.badge {
  display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px;
  border: 1px solid currentColor; margin-left: 6px; vertical-align: 1px;
}
.badge--warn { color: var(--warn); }
.badge--ok { color: var(--ok); }
.badge--err { color: var(--danger); }

.tech { font-size: 13px; }
.tech dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
.tech dt { color: var(--ink-soft); }
.tech dd { margin: 0; font-variant-numeric: tabular-nums; }

/* ───────────────────────── Campi ───────────────────────── */

.field-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--ink-soft); flex: 1 1 180px; }
.field input, .field select {
  font: inherit; color: var(--ink); padding: 9px 10px;
  border: 1px solid var(--rule-strong); border-radius: 8px; background: #fff;
  min-height: 42px;
}
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.card-preview { margin-top: 14px; }
.card-preview img { width: 100%; height: auto; border: 1px solid var(--rule); border-radius: 6px; }

.text-output { margin-top: 12px; }
.text-output pre {
  background: #f7f9fb; border: 1px solid var(--rule); border-radius: 8px;
  padding: 12px; overflow-x: auto; font-size: 12.5px; line-height: 1.35;
}

/* ═══════════════════════ §23 MIRINO — tema scuro ═══════════════════════ */

.vf {
  position: fixed; inset: 0; z-index: 40;
  background: #05080c; color: #eef3f8;
  display: flex; flex-direction: column;
  overscroll-behavior: contain;
}
.vf__stage { position: absolute; inset: 0; overflow: hidden; background: #000; }
.vf__video, .vf__overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
.vf__video { object-fit: cover; }
.vf__overlay { pointer-events: none; }

.vf__top {
  position: relative; z-index: 2;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 0;
  display: grid; justify-items: center; gap: 2px;
}
.vf__icon {
  position: absolute; left: 12px; top: calc(env(safe-area-inset-top, 0px) + 10px);
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(0,0,0,0.5); color: #fff; border: 1px solid rgba(255,255,255,0.25);
  font-size: 18px; cursor: pointer;
}
.vf__badge {
  font-size: 40px; font-weight: 700; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 12px rgba(0,0,0,0.9);
}
.vf__hint {
  font-size: 17px; font-weight: 600; text-transform: lowercase;
  color: #ffd166; text-shadow: 0 2px 8px rgba(0,0,0,0.9);
  min-height: 24px;
}
.vf__hint[data-ok="1"] { color: #7ee2a8; }
.vf__mode {
  position: absolute; right: 12px; top: calc(env(safe-area-inset-top, 0px) + 18px);
  font-size: 12px; opacity: 0.8;
}

.vf__side {
  position: absolute; right: 12px; bottom: calc(env(safe-area-inset-bottom, 0px) + 130px);
  z-index: 2; display: grid; gap: 8px; justify-items: end;
}
.vf__pill {
  background: rgba(0,0,0,0.55); color: #fff; border: 1px solid rgba(255,255,255,0.25);
  border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 13px; cursor: pointer;
}
.vf__samples { font-size: 12px; opacity: 0.8; font-variant-numeric: tabular-nums; }

.vf__bottom {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  padding: 0 24px calc(env(safe-area-inset-bottom, 0px) + 22px);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.vf__shutter {
  flex: 1; max-width: 260px; margin: 0 auto;
  height: 68px; border-radius: 34px;
  background: #fff; color: #0d3b66;
  border: none; box-shadow: 0 4px 0 #b9c6d2;
  font: inherit; font-size: 20px; font-weight: 800; letter-spacing: 0.06em;
  cursor: pointer;
}
.vf__shutter:active { transform: translateY(4px); box-shadow: 0 0 0 #b9c6d2; }
.vf__shutter[data-state="wait"] { background: #ffd166; }
.vf__shutter[data-state="blocked"] { background: #6b7480; color: #dfe6ec; }
.vf__round {
  width: 52px; height: 52px; flex: none; border-radius: 50%;
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.3);
  color: #fff; display: grid; place-items: center; cursor: pointer;
}
.vf__round svg { width: 24px; height: 24px; }
.vf__round[aria-pressed="true"] { background: #ffd166; color: #05080c; }

.vf__toast {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 108px);
  transform: translateX(-50%); z-index: 3;
  background: rgba(0,0,0,0.8); border: 1px solid rgba(255,255,255,0.2);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; max-width: 88vw; text-align: center;
}

/* ═══════════════════════ §26 EDITOR — fullscreen ═══════════════════════ */

.ed {
  position: fixed; inset: 0; z-index: 50;
  background: #05080c; color: #eef3f8;
  touch-action: none; overscroll-behavior: contain;
}
.ed__canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.ed__top {
  position: absolute; left: 0; right: 0; top: 0; z-index: 2;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(rgba(0,0,0,0.75), rgba(0,0,0,0));
}
.ed__icon {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  background: rgba(0,0,0,0.5); color: #fff; border: 1px solid rgba(255,255,255,0.25);
  font-size: 17px; cursor: pointer;
}
.ed__label { flex: 1; font-size: 15px; font-weight: 600; }
.ed__zoom { font-size: 13px; opacity: 0.75; font-variant-numeric: tabular-nums; }
.ed__bottom {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  padding: 14px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,0.8));
}
.ed__progress { font-size: 13px; opacity: 0.8; font-variant-numeric: tabular-nums; }
.ed__tools {
  position: absolute; right: 12px; top: calc(env(safe-area-inset-top, 0px) + 58px);
  z-index: 2; display: grid; gap: 8px; justify-items: end;
}

/* ───────────────────────── Dialoghi ───────────────────────── */

.dlg {
  border: 1px solid var(--rule); border-radius: 14px; padding: 0;
  max-width: 480px; width: calc(100vw - 32px);
  box-shadow: 0 18px 48px rgba(8, 30, 55, 0.28);
}
.dlg::backdrop { background: rgba(8, 20, 32, 0.5); }
.dlg__form { padding: 18px; }
.dlg__title { font-size: 17px; color: var(--primary); margin-bottom: 8px; }
.dlg__body { font-size: 14px; color: var(--ink); }
.dlg__body .field { margin-top: 10px; }
.dlg__menu { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 0 0; margin: 0; }

@media (max-width: 520px) {
  .bench { padding: 0 12px 40px; }
  .step { flex-direction: column; align-items: stretch; }
  .step__actions { justify-content: space-between; }
}

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
}
