:root {
  --ground: #23324D;
  --surface: #2F4266;
  --surface-hover: #38507C;
  --ink: #F4F1EA;
  --muted: #C8CFDC;
  --accent: #C9A24A;
  --accent-hover: #D6B15E;
  --on-accent: #1B2740;
  --danger: #F0A5A0;
  --gutter: 20px;
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --drawer: cubic-bezier(0.32, 0.72, 0, 1);
}
* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; background: var(--ground); overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
body {
  background: var(--ground); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-size: 16px; line-height: 1.5; min-height: 100vh; min-height: 100dvh;
}
button, a, label.switch, .swatch { touch-action: manipulation; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
img { display: block; }

.app { max-width: 640px; margin: 0 auto; padding: max(20px, env(safe-area-inset-top)) var(--gutter) calc(32px + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 12px 0 18px; }
h1 { font-size: clamp(2rem, 9vw, 2.75rem); line-height: 1; letter-spacing: -0.03em; font-weight: 700; }
.status { margin-top: 8px; color: var(--muted); font-size: 0.9375rem; }
h2 { font-size: 1.25rem; font-weight: 600; letter-spacing: -0.01em; margin-bottom: 8px; }
h2.sub { margin-top: 40px; }
.lead { color: var(--muted); margin-bottom: 18px; max-width: 52ch; }
.note { color: var(--muted); font-size: 0.9375rem; margin-top: 12px; max-width: 52ch; }
.note.center { text-align: center; }

/* bottoni */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border: 0; border-radius: 0; text-decoration: none;
  font-weight: 600; font-size: 1rem; white-space: nowrap;
  transition: transform 140ms var(--ease), background-color 140ms var(--ease), opacity 140ms var(--ease);
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2px var(--accent); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.small { min-height: 44px; padding: 0 12px; font-size: 0.9375rem; background: var(--ground); color: var(--ink); }
.btn.wide { width: 100%; min-height: 64px; font-size: 1.125rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible, .tabs button:focus-visible, .swatch:focus-visible, input:focus-visible, select:focus-visible, .switch input:focus-visible + .track { outline: 3px solid var(--ink); outline-offset: 3px; }
@media (hover: hover) and (pointer: fine) {
  .btn.primary:hover { background: var(--accent-hover); }
  .btn.ghost:hover { background: var(--surface); }
  .btn.small:hover { background: var(--surface-hover); }
}

/* schede: su telefono barra fissa in basso, sotto il pollice */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--ground); padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  gap: 6px;
}
.tabs button {
  min-height: 52px; border: 0; border-radius: 0; background: transparent; color: var(--muted); font-weight: 600; font-size: 0.9375rem;
  transition: background-color 140ms var(--ease), color 140ms var(--ease), transform 140ms var(--ease);
}
.tabs button:active { transform: scale(0.97); }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--on-accent); }
.app { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

/* pannelli */
.panel { animation: fadein 200ms var(--ease); }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }

/* campi */
.fields { display: grid; gap: 14px; margin-top: 4px; }
.field { display: grid; gap: 6px; }
.field > span:first-child { font-size: 0.9375rem; color: var(--muted); font-weight: 500; }
input[type="text"], input:not([type]), input[type="tel"], input[type="email"], input[type="url"], input[type="search"], select {
  width: 100%; min-height: 56px; padding: 0 18px; border: 0; border-radius: 0; background: var(--surface); color: var(--ink);
  font: inherit; font-size: 1rem; -webkit-appearance: none; appearance: none;
}
input::placeholder { color: var(--muted); opacity: 0.8; }
.prefix { display: flex; align-items: stretch; background: var(--surface); }
.prefix .pre { display: flex; align-items: center; padding-left: 18px; color: var(--muted); white-space: nowrap; }
.prefix input { background: transparent; padding-left: 0; min-width: 0; }

/* interruttore */
.switch { display: flex; align-items: center; gap: 14px; min-height: 56px; margin-bottom: 14px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.track { flex: none; width: 56px; height: 32px; background: var(--surface); position: relative; transition: background-color 160ms var(--ease); }
.track::after { content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; background: var(--ink); transition: transform 180ms var(--ease), background-color 160ms var(--ease); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(24px); background: var(--on-accent); }
.switch-text { font-weight: 500; }
.fields.off { opacity: 0.4; pointer-events: none; transition: opacity 160ms var(--ease); }

/* lista lingue */
.langs { list-style: none; padding: 0; display: grid; gap: 12px; margin-bottom: 16px; }
.lang-row { background: var(--surface); padding: 16px; display: grid; gap: 12px; transition: opacity 180ms var(--ease), transform 180ms var(--ease); }
.lang-row.enter { opacity: 0; transform: translateY(8px); }
.lang-row.leave { opacity: 0; transform: scale(0.98); }
.lang-head { display: flex; align-items: center; gap: 14px; }
.lang-head img { width: 48px; height: 36px; object-fit: cover; flex: none; }
.lang-name { font-size: 1.1875rem; font-weight: 700; letter-spacing: -0.01em; }
.badge { margin-left: 8px; font-size: 0.8125rem; font-weight: 600; background: var(--accent); color: var(--on-accent); padding: 2px 8px; vertical-align: 2px; }
.lang-file { color: var(--muted); font-size: 0.9375rem; overflow-wrap: anywhere; }
.lang-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.lang-flag { display: grid; gap: 6px; }
.lang-flag span { font-size: 0.875rem; color: var(--muted); }
.lang-flag select { min-height: 48px; background: var(--ground); font-size: 1rem; }
.empty { background: var(--surface); padding: 24px 18px; color: var(--muted); }

/* colori */
.swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.swatch { border: 0; border-radius: 0; padding: 0; min-height: 88px; display: flex; flex-direction: column; justify-content: flex-end; align-items: flex-start; gap: 8px; padding: 12px; text-align: left; box-shadow: inset 0 0 0 2px transparent; transition: transform 140ms var(--ease), box-shadow 140ms var(--ease); }
.swatch:active { transform: scale(0.97); }
.swatch .dot { width: 28px; height: 8px; }
.swatch .nm { font-weight: 600; font-size: 0.9375rem; }
.swatch[aria-checked="true"] { box-shadow: inset 0 0 0 3px #F4F1EA; }

/* QR e carta */
.linkbox .row, .row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.qr { background: #fff; width: 252px; padding: 16px; }
.qr svg { display: block; width: 220px; height: 220px; }
.card { padding: 20px; max-width: 360px; display: grid; gap: 14px; margin-bottom: 4px; }
.card-top { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.card-name { font-size: 1.125rem; }
.card-l { display: block; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.card-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; font-weight: 600; font-size: 0.9375rem; }
.card-grid > div { display: grid; gap: 2px; }
.card-qr { width: 88px; height: 88px; background: #F4F1EA; margin: 4px auto 0; }

/* anteprima: colonna fissa su schermo largo */
.preview-col { display: none; }
.overlay { position: fixed; inset: 0; z-index: 20; background: var(--ground); display: flex; flex-direction: column; animation: fadein 200ms var(--ease); }
.overlay-bar { display: flex; align-items: center; justify-content: space-between; padding: max(12px, env(safe-area-inset-top)) var(--gutter) 12px; font-weight: 600; }
.overlay iframe { flex: 1; border: 0; width: 100%; background: var(--ground); }
.phone { border: 3px solid var(--surface); width: 360px; height: 720px; background: var(--ground); }
.phone iframe { width: 100%; height: 100%; border: 0; }

/* scelta lingua: foglio dal basso */
.sheet-wrap { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet-bg { position: absolute; inset: 0; background: rgba(10, 15, 26, 0.6); opacity: 0; transition: opacity 220ms var(--ease); }
.sheet {
  position: relative; width: 100%; max-width: 640px; max-height: 86dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--ground); padding: 20px var(--gutter) max(24px, env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform 280ms var(--drawer);
}
.sheet-wrap.open .sheet-bg { opacity: 1; }
.sheet-wrap.open .sheet { transform: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; }
.catalog { list-style: none; padding: 0; display: grid; gap: 6px; margin-top: 12px; }
.catalog button { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; padding: 0 18px; border: 0; border-radius: 0; background: var(--surface); text-align: left; font-weight: 600; font-size: 1.0625rem; transition: transform 140ms var(--ease), background-color 140ms var(--ease); }
.catalog button:active { transform: scale(0.98); }
.catalog img { width: 36px; height: 27px; object-fit: cover; }
@media (hover: hover) and (pointer: fine) { .catalog button:hover { background: var(--surface-hover); } }

/* avviso */
.toast { position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translate(-50%, 12px); background: var(--ink); color: var(--ground); padding: 12px 18px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity 180ms var(--ease), transform 180ms var(--ease); z-index: 40; max-width: calc(100vw - 40px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* schermo largo: schede in alto, anteprima a fianco */
@media (min-width: 960px) {
  .app { max-width: 1080px; padding-bottom: 48px; }
  .only-small { display: none; }
  .tabs { position: static; display: flex; gap: 6px; padding: 0 0 24px; background: transparent; }
  .tabs button { padding: 0 22px; }
  .layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 56px; align-items: start; }
  .preview-col { display: block; position: sticky; top: 24px; }
  .toast { bottom: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .overlay { animation: none; }
  .sheet, .sheet-bg, .btn, .track::after, .lang-row { transition-duration: 1ms; }
  .btn:active:not(:disabled), .tabs button:active, .swatch:active, .catalog button:active { transform: none; }
}

/* accesso */
.login { min-height: 100dvh; display: grid; place-items: center; padding: max(24px, env(safe-area-inset-top)) var(--gutter) max(24px, env(safe-area-inset-bottom)); }
.login-box { width: 100%; max-width: 440px; display: grid; gap: 16px; }
.login h1 { font-size: clamp(2.75rem, 14vw, 4rem); }
.login form { display: grid; gap: 16px; }

/* accesso: separatore; scelte a due; colori su misura; spunte */
.or { text-align: center; color: var(--muted); font-size: 0.9375rem; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg button { min-height: 52px; border: 0; border-radius: 0; background: var(--surface); font-weight: 600; transition: background-color 140ms var(--ease), color 140ms var(--ease), transform 140ms var(--ease); }
.seg button:active { transform: scale(0.97); }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--on-accent); }
.seg button:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.custom { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.field.color input { width: 100%; height: 56px; padding: 4px; border: 0; background: var(--surface); }
.checks { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 16px; background: var(--surface); font-weight: 600; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.card-done { margin-top: 18px; }

/* riga CV compatta: bandiera, nome e "Cambia PDF" sulla stessa riga; il resto sotto "Altro" */
.lang-row { grid-template-columns: 1fr auto; align-items: center; gap: 10px 12px; }
.lang-row .more { grid-column: 1 / -1; }
.lang-row .btn.ghost { min-height: 44px; padding: 0 14px; font-size: 0.9375rem; }
.more summary { list-style: none; cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--muted); font-weight: 600; font-size: 0.9375rem; }
.more summary::-webkit-details-marker { display: none; }
.more summary::after { content: ""; width: 8px; height: 8px; margin-left: 10px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg) translateY(-2px); transition: transform 160ms var(--ease); }
.more[open] summary::after { transform: rotate(225deg); }
.more summary:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.more-body { display: grid; gap: 12px; padding-top: 4px; }
@media (max-width: 400px) { .lang-row { grid-template-columns: 1fr; } .lang-row .btn.ghost { justify-self: start; } }

.lnk { color: var(--ink); text-underline-offset: 3px; }
#top-link { display: inline-block; margin-top: 4px; font-size: 0.9375rem; font-weight: 600; }
.made a:focus-visible, .lnk:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
