/* SaVerio — interfaccia del partecipante. Nessuna libreria esterna. */
:root {
  --accent: #544a7c;
  --accent-hover: #463d68;
  --accent-ink: #544a7c;
  --accent-soft: #ece9f5;
  --on-accent: #ffffff;
  --bg: #f4f3f7;
  --surface: #ffffff;
  --surface-2: #f7f6fa;
  --bubble: #eeecf4;
  --text: #1f1d26;
  --muted: #5e5b6a;
  --border: #dcd9e4;
  --focus: #7b6fb0;
  --info: #2a6782;
  --warn-bg: #fff1cc;
  --warn-ink: #6e4b00;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --q-correct: #1e7a3c;
  --q-acceptable: #1f6f8b;
  --q-useless: #765f00;
  --q-wrong: #a94f00;
  --q-dangerous: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #6c61a0;
    --accent-hover: #7b70b0;
    --accent-ink: #c4bcf0;
    --accent-soft: #2c2840;
    --bg: #131218;
    --surface: #1c1b23;
    --surface-2: #23212c;
    --bubble: #2c2a37;
    --text: #ece9f3;
    --muted: #aaa6b8;
    --border: #383445;
    --focus: #b3a8ec;
    --info: #86c4de;
    --warn-bg: #3d3112;
    --warn-ink: #f2d27a;
    --danger: #f2948c;
    --danger-bg: #3a1d1b;
    --q-correct: #7fd49a;
    --q-acceptable: #86c4de;
    --q-useless: #e0c75a;
    --q-wrong: #f0a35e;
    --q-dangerous: #f2948c;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 4px 16px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1, h2, p, ul, ol { margin: 0; }
h1 { font-size: 1.5rem; line-height: 1.25; }
h2 { font-size: 1.05rem; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.pre { white-space: pre-wrap; }
.nojs { padding: 16px; }

/* Pulsanti */
.btn {
  min-height: 44px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover:not(:disabled) { border-color: var(--accent-ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { padding: 6px 14px; font-size: .9rem; }

/* Pagine (avvio, fine, avvisi) */
.page, .notice {
  min-height: 100vh; min-height: 100dvh; padding: 24px 16px;
  display: flex; justify-content: center; align-items: flex-start;
}
.notice { align-items: center; text-align: center; }
.card-panel {
  width: 100%; max-width: 660px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 24px; display: flex; flex-direction: column; gap: 16px;
}
.brand { color: var(--accent-ink); font-weight: 700; font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; }
.lead { font-size: 1.05rem; }
section { display: grid; gap: 8px; }
.patient-card { display: flex; gap: 14px; align-items: flex-start; background: var(--surface-2); border-radius: 12px; padding: 14px; }
.pname { font-weight: 700; }
.howto, .missed { padding-left: 1.2em; display: grid; gap: 6px; }
.consent {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px;
  border: 1px solid var(--border); border-radius: 12px; cursor: pointer;
}
.consent input { width: 22px; height: 22px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.form-err { color: var(--danger); }
.form-err:empty { display: none; }
@media (max-width: 480px) {
  .page { padding: 16px; }
  .card-panel { padding: 18px; }
}

/* Avatar */
.avatar {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; font-size: .8rem;
}
.avatar.lg { width: 52px; height: 52px; font-size: 1.1rem; }

/* Visita */
.visit {
  display: flex; flex-direction: column; height: 100vh; height: 100dvh;
  max-width: 880px; margin: 0 auto; background: var(--surface);
}
@media (min-width: 900px) { .visit { border-inline: 1px solid var(--border); } }
.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.who { flex: 1; min-width: 0; }
.who .pname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage { font-size: .85rem; color: var(--muted); }
.top .brand { flex: none; }
@media (max-width: 420px) { .top .brand { display: none; } }

.pending {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 16px;
  background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: .85rem;
}
.chip {
  display: inline-flex; gap: 6px; align-items: center; padding: 2px 4px 2px 10px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
}
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 700; line-height: 1.4; white-space: nowrap; }
.badge.wait { background: var(--warn-bg); color: var(--warn-ink); }

.log {
  flex: 1; overflow-y: auto; padding: 16px; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 10px;
}
.row { display: flex; gap: 8px; align-items: flex-end; max-width: 88%; }
.row.me { align-self: flex-end; }
.bubble { padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.patient .bubble { background: var(--bubble); border-bottom-left-radius: 6px; }
.me .bubble { background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 6px; }
.bubble.faded { opacity: .6; }
.sys { align-self: center; text-align: center; font-size: .8rem; color: var(--muted); max-width: 90%; }
.stage-line {
  align-self: stretch; text-align: center; font-size: .85rem; color: var(--muted);
  padding: 8px 0; margin: 4px 0; border-block: 1px dashed var(--border);
}
.stage-title { font-weight: 700; color: var(--accent-ink); }
.card {
  align-self: flex-start; max-width: 92%; display: grid; gap: 6px; font-size: .92rem;
  background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--accent-ink);
  border-radius: 10px; padding: 10px 14px;
}
.card.report { border-left-color: var(--info); }
.card-title { font-weight: 700; font-size: .85rem; color: var(--accent-ink); }
.card.report .card-title { color: var(--info); }
.card-sub { font-weight: 600; color: var(--text); }
.source { font-size: .78rem; color: var(--muted); }
.typing { align-self: flex-start; color: var(--muted); font-style: italic; font-size: .9rem; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .typing { animation: none; } }
@media (min-width: 640px) { .card, .typing { margin-left: 40px; } }
.failed { align-self: stretch; display: grid; gap: 8px; justify-items: end; }
.alert {
  justify-self: stretch; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  background: var(--danger-bg); color: var(--danger); border: 1px solid currentColor;
  border-radius: 10px; padding: 8px 12px; font-size: .9rem;
}
.alert p { flex: 1; min-width: 12em; }

.composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 16px; border-top: 1px solid var(--border); }
.composer textarea {
  flex: 1; min-width: 0; min-height: 44px; max-height: calc(1.4em * 5 + 22px); resize: none; overflow-y: auto;
  padding: 10px 14px; font: inherit; line-height: 1.4; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
}
.composer textarea:focus-visible { outline-offset: 0; }
.send { flex: none; }
.tools {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  padding: 0 16px calc(10px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .tools { grid-template-columns: repeat(4, 1fr); } }
.tool { font-size: .9rem; padding: 8px 10px; }
.tool.end { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }

/* Finestre (elenco azioni, conferma) */
.sheet {
  border: none; padding: 0; border-radius: 16px; overflow: auto;
  width: min(440px, calc(100% - 32px)); max-height: 80vh;
  background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgb(0 0 0 / .25);
}
.sheet::backdrop { background: rgb(20 16 36 / .45); }
.sheet-body { padding: 16px; display: grid; gap: 12px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.icon-btn {
  min-width: 44px; min-height: 44px; border: none; border-radius: 10px;
  background: transparent; color: var(--muted); font-size: 1.6rem; line-height: 1; cursor: pointer;
}
.pick { list-style: none; padding: 0; display: grid; gap: 8px; }
.pick-btn {
  width: 100%; min-height: 48px; padding: 10px 14px; text-align: left; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text); font: inherit;
}
.pick-btn:hover:not(:disabled) { border-color: var(--accent-ink); }
.pick-btn:disabled { cursor: default; color: var(--muted); }
.done { font-size: .8rem; font-weight: 700; color: var(--q-correct); white-space: nowrap; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
@media (max-width: 639px) {
  .sheet { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 16px 16px 0 0; max-height: 85dvh; }
  .sheet-body { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .dlg-actions .btn { flex: 1; }
}

/* Fine */
.score { display: grid; gap: 12px; }
.bar-head { display: flex; justify-content: space-between; font-size: .9rem; }
.track { height: 10px; background: var(--accent-soft); border-radius: 999px; overflow: hidden; }
.fill { height: 100%; background: var(--accent-ink); border-radius: 999px; }
.bar.total .bar-head { font-weight: 700; font-size: 1rem; }
.bar.total .track { height: 14px; }
.choices { list-style: none; padding: 0; display: grid; gap: 10px; }
.choice { border: 1px solid var(--border); border-radius: 10px; padding: 12px; display: grid; gap: 4px; }
.choice-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; font-weight: 600; }
.q-correct { --q: var(--q-correct); }
.q-acceptable { --q: var(--q-acceptable); }
.q-useless { --q: var(--q-useless); }
.q-wrong { --q: var(--q-wrong); }
.q-dangerous { --q: var(--q-dangerous); }
.badge.q {
  color: var(--q); background: color-mix(in srgb, var(--q) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--q) 45%, transparent);
}
.restart { border-top: 1px solid var(--border); padding-top: 16px; justify-items: start; }
@media (max-width: 480px) { .restart .btn { width: 100%; } }
