/* MyPolimedica — design system.
   Brand: arancio PMF su carta calda. Nunito (UI) + Fraunces (voce editoriale).
   Firma visiva: ticket appuntamento + filo arancio (timeline).
   Tema: auto (prefers-color-scheme) + override manuale via [data-theme]. */

:root {
  --brand: #F39200;
  --brand-deep: #C47500;
  --brand-press: #A96400;
  --brand-tint: #FFF4E3;
  --brand-tint-2: #FCE7C8;
  --paper: #FAF7F2;
  --card: #FFFFFF;
  --card-2: #F6F1EA;
  --ink: #241C15;
  --ink-2: #6E6459;
  --ink-3: #A79C90;
  --line: rgba(36, 28, 21, 0.10);
  --line-2: rgba(36, 28, 21, 0.18);
  --ok: #1E8449;
  --ok-tint: #E8F6EE;
  --danger: #C0392B;
  --danger-tint: #FBEDEB;
  --shadow: 0 2px 14px rgba(90, 62, 20, 0.08);
  --shadow-lg: 0 10px 34px rgba(90, 62, 20, 0.16);
  --r: 16px;
  --r-sm: 10px;
  --nav-h: 64px;
  color-scheme: light;
}
[data-theme="dark"] {
  --brand-tint: #33230A;
  --brand-tint-2: #4A320D;
  --paper: #141210;
  --card: #1F1B18;
  --card-2: #292420;
  --ink: #F5EFE7;
  --ink-2: #B4A99D;
  --ink-3: #7A7167;
  --line: rgba(245, 239, 231, 0.10);
  --line-2: rgba(245, 239, 231, 0.20);
  --ok: #4CC38A;
  --ok-tint: #12291C;
  --danger: #E5695B;
  --danger-tint: #341613;
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 10px 34px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-tint: #33230A;
    --brand-tint-2: #4A320D;
    --paper: #141210;
    --card: #1F1B18;
    --card-2: #292420;
    --ink: #F5EFE7;
    --ink-2: #B4A99D;
    --ink-3: #7A7167;
    --line: rgba(245, 239, 231, 0.10);
    --line-2: rgba(245, 239, 231, 0.20);
    --ok: #4CC38A;
    --ok-tint: #12291C;
    --danger: #E5695B;
    --danger-tint: #341613;
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 10px 34px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
img { max-width: 100%; }
button { font-family: inherit; }
a { color: var(--brand-deep); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

.display { font-family: 'Fraunces', Georgia, serif; font-weight: 600; letter-spacing: -0.01em; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- shell */
#app { min-height: 100dvh; display: flex; flex-direction: column; }
.layout { flex: 1; display: flex; min-height: 100dvh; }
.main {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + 24px);
}
@media (min-width: 960px) {
  .main { max-width: 860px; padding: 28px 40px 60px; }
}

/* topbar mobile */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px calc(10px);
  padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar .logo { width: 34px; height: 34px; border-radius: 9px; background: #fff; padding: 3px; box-shadow: var(--shadow); }
.topbar .title { font-weight: 800; font-size: 17px; flex: 1; }
.topbar .title small { display: block; font-size: 11px; font-weight: 600; color: var(--ink-2); line-height: 1.2; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink-2); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.iconbtn:hover { background: var(--brand-tint); color: var(--brand-deep); }
.iconbtn svg { width: 20px; height: 20px; }

/* bottom nav (mobile) */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.bottomnav button {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--ink-3); font-size: 10.5px; font-weight: 700; letter-spacing: .02em;
  transition: color .15s; min-height: 44px;
}
.bottomnav button svg { width: 23px; height: 23px; }
.bottomnav button.on { color: var(--brand-deep); }
.bottomnav button.on svg { color: var(--brand); }

/* sidebar (desktop) */
.sidebar { display: none; }
@media (min-width: 960px) {
  .bottomnav, .topbar { display: none; }
  .sidebar {
    display: flex; flex-direction: column;
    width: 248px; flex-shrink: 0;
    position: sticky; top: 0; height: 100dvh;
    background: var(--card);
    border-right: 1px solid var(--line);
    padding: 22px 14px 18px;
  }
  .sidebar .brand { display: flex; align-items: center; gap: 11px; padding: 0 10px 20px; }
  .sidebar .brand img { width: 42px; height: 42px; border-radius: 11px; background: #fff; padding: 4px; box-shadow: var(--shadow); }
  .sidebar .brand b { font-size: 17px; }
  .sidebar .brand small { display: block; font-size: 11px; color: var(--ink-2); font-weight: 600; }
  .sidebar nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }
  .sidebar nav .sep { margin: 10px 10px 6px; font-size: 10.5px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
  .sidebar nav button {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 12px; border: none; border-radius: 11px;
    background: none; color: var(--ink-2); font-size: 14.5px; font-weight: 700;
    cursor: pointer; text-align: left; transition: background .13s, color .13s;
  }
  .sidebar nav button svg { width: 20px; height: 20px; }
  .sidebar nav button:hover { background: var(--brand-tint); color: var(--brand-deep); }
  .sidebar nav button.on { background: var(--brand-tint); color: var(--brand-deep); }
  .sidebar .foot { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 2px; }
  .pagegrid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
}
@media (max-width: 959px) { .pagegrid { display: block; } }

/* ---------------------------------------------------------------- primitives */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.card h2 { font-size: 16.5px; font-weight: 800; margin-bottom: 10px; }
.eyebrow { font-size: 11px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 6px; }
.pagetitle { font-family: 'Fraunces', Georgia, serif; font-weight: 600; font-size: 27px; letter-spacing: -0.01em; margin: 8px 0 16px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.center { text-align: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 50px; padding: 12px 18px;
  border: none; border-radius: 14px; cursor: pointer;
  font-size: 15.5px; font-weight: 800; letter-spacing: .01em;
  transition: transform .1s, background .15s, box-shadow .15s;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn svg { width: 19px; height: 19px; flex-shrink: 0; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-deep); box-shadow: 0 6px 18px rgba(243, 146, 0, .3); }
.btn-primary:active:not(:disabled) { transform: scale(.985); }
.btn-ghost { background: var(--card); color: var(--brand-deep); border: 1.5px solid var(--brand); }
.btn-ghost:hover:not(:disabled) { background: var(--brand-tint); }
.btn-quiet { background: var(--card-2); color: var(--ink-2); }
.btn-quiet:hover:not(:disabled) { background: var(--brand-tint); color: var(--brand-deep); }
.btn-danger { background: none; color: var(--danger); border: 1.5px solid var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-tint); }
.btn-sm { min-height: 40px; width: auto; padding: 8px 16px; font-size: 13.5px; border-radius: 11px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

.backlink {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: none; cursor: pointer; padding: 6px 0;
  color: var(--brand-deep); font-size: 14px; font-weight: 800;
}
.backlink svg { width: 17px; height: 17px; }

label.field { display: block; font-size: 13px; font-weight: 800; color: var(--ink-2); margin-bottom: 14px; }
label.field > span.lbl { display: block; margin-bottom: 6px; text-transform: uppercase; letter-spacing: .06em; font-size: 11px; }
input[type=text], input[type=tel], input[type=email], input[type=date], input[type=search], input[type=password], textarea, select {
  width: 100%; padding: 13px 14px;
  border: 1.5px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--card); color: var(--ink);
  font-family: inherit; font-size: 16px;
  transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand); }
textarea { resize: none; min-height: 84px; }

.err {
  background: var(--danger-tint); border: 1.5px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger); border-radius: var(--r-sm);
  padding: 11px 14px; font-size: 13.5px; font-weight: 700; margin-bottom: 12px;
}
.err.shake { animation: shake .35s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); } 20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(4px); }
}
.okbox {
  background: var(--ok-tint); border: 1.5px solid color-mix(in srgb, var(--ok) 40%, transparent);
  color: var(--ok); border-radius: var(--r-sm);
  padding: 11px 14px; font-size: 13.5px; font-weight: 700; margin-bottom: 12px;
}
.notice {
  background: var(--brand-tint); border: 1.5px solid var(--brand-tint-2);
  color: var(--brand-deep); border-radius: var(--r-sm);
  padding: 11px 14px; font-size: 13px; font-weight: 600; margin-bottom: 14px; line-height: 1.55;
}
.hidden { display: none !important; }

/* liste selezionabili */
.pick { display: flex; flex-direction: column; gap: 8px; }
.pick-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 13px 14px; border: 1.5px solid var(--line); border-radius: 13px;
  background: var(--card); color: var(--ink); cursor: pointer; text-align: left;
  font-size: 15px; font-weight: 700; transition: border-color .13s, background .13s;
  min-height: 52px;
}
.pick-item:hover { border-color: var(--brand); background: var(--brand-tint); }
.pick-item small { display: block; font-weight: 600; font-size: 12.5px; color: var(--ink-2); }
.pick-item .grow { flex: 1; }
.pick-item .chev { color: var(--ink-3); flex-shrink: 0; }
.pick-item .chev svg { width: 18px; height: 18px; }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  background: var(--brand-tint); color: var(--brand-deep);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px; overflow: hidden;
  border: 1.5px solid var(--brand-tint-2);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* chips / pillole */
.chips { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; margin-bottom: 12px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; padding: 8px 15px; border-radius: 20px;
  border: 1.5px solid var(--line-2); background: var(--card);
  font-size: 13px; font-weight: 700; color: var(--ink-2); cursor: pointer;
  transition: all .13s; min-height: 36px;
}
.chip:hover { border-color: var(--brand); color: var(--brand-deep); }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* slot orari */
.slots { display: flex; flex-wrap: wrap; gap: 8px; }
.slot {
  padding: 10px 14px; min-width: 72px; min-height: 44px;
  border-radius: 22px; border: 1.5px solid var(--line-2);
  background: var(--card); color: var(--ink); cursor: pointer;
  font-size: 14.5px; font-weight: 800; font-variant-numeric: tabular-nums;
  display: flex; flex-direction: column; align-items: center; line-height: 1.25;
  transition: all .12s;
}
.slot small { font-size: 10px; font-weight: 700; color: var(--ink-3); }
.slot:hover { border-color: var(--brand); background: var(--brand-tint); }
.slot.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.slot.on small { color: rgba(255, 255, 255, .85); }
.slot:active { transform: scale(.95); }

/* dot medico */
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

/* icone SVG inline dentro testo/avatar: senza misura esplicita l'SVG si
   allarga al 100% del contenitore (scudo gigante nei referti) */
p svg, .avatar svg { width: 18px; height: 18px; flex-shrink: 0; }
.avatar svg { width: 22px; height: 22px; }

/* ---------------------------------------------------------------- calendario disponibilita' 4 settimane */
.mpcal { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 14px; }
.mpcal .c-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 8px; background: var(--brand-tint); border-bottom: 1px solid var(--line);
}
.mpcal .c-head h3 { font-size: 14.5px; font-weight: 800; color: var(--brand-deep); font-variant-numeric: tabular-nums; text-align: center; flex: 1; }
.mpcal .c-nav {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--brand-deep); font-weight: 800; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.mpcal .c-nav svg { width: 18px; height: 18px; }
.mpcal .c-nav:disabled { opacity: .3; cursor: default; }
.mpcal table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.mpcal th {
  padding: 7px 0; font-size: 11.5px; font-weight: 800; text-transform: uppercase;
  letter-spacing: .04em; color: var(--ink-2); background: var(--card-2);
  border-bottom: 1px solid var(--line);
}
.mpcal td { border: 1px solid var(--line); padding: 0; height: 58px; vertical-align: top; }
.mpcal td button.c-day {
  width: 100%; height: 100%; min-height: 58px; border: none; background: transparent;
  cursor: default; padding: 4px 2px 3px; display: flex; flex-direction: column;
  align-items: center; gap: 3px; color: var(--ink); border-radius: 0;
}
.mpcal td .c-num { font-size: 12.5px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.mpcal td.is-past .c-num, .mpcal td.is-empty .c-num { color: var(--ink-3); font-weight: 600; }
.mpcal td.has-slots button.c-day { cursor: pointer; }
.mpcal td.has-slots:hover button.c-day { background: var(--brand-tint); }
.mpcal td.is-today { box-shadow: inset 0 0 0 2px var(--brand); }
.mpcal td.is-sel button.c-day { background: var(--brand-tint); box-shadow: inset 0 -3px 0 var(--brand); }
.mpcal .c-dots { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; align-content: flex-start; }
.mpcal .c-dot {
  min-width: 24px; height: 22px; padding: 0 4px; border-radius: 11px;
  color: #fff; font-size: 12px; font-weight: 800; line-height: 22px; text-align: center;
  font-variant-numeric: tabular-nums;
}
.mpcal .c-dot-more { background: var(--ink-3); }
/* mono-operatore / filtro: pillola "N posti" a larghezza cella */
.mpcal .c-posti {
  display: block; margin: 2px 3px 0; padding: 2px 4px; border-radius: 9px;
  background: var(--brand); color: #fff; font-size: 11px; font-weight: 800;
  text-align: center; font-variant-numeric: tabular-nums; line-height: 1.35;
}
.mpcal .c-posti.scarso { background: #C98A00; } /* ambra "quasi pieno" (mai rosso) */

/* legenda potenziata: pallino + foto + nome + 1° orario, tappabile = filtro */
.cal-legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 2px 12px; }
.cal-legend .l-item {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px 6px 8px;
  border: 1.5px solid var(--line-2); border-radius: 14px; background: var(--card);
  cursor: pointer; text-align: left;
}
.cal-legend .l-item.on { border-color: var(--brand); background: var(--brand-tint); }
.cal-legend .l-item .avatar { width: 36px; height: 36px; font-size: 12px; }
.cal-legend .l-item .l-txt { display: flex; flex-direction: column; line-height: 1.2; }
.cal-legend .l-item .l-txt b { font-size: 13px; font-weight: 800; color: var(--ink); }
.cal-legend .l-item .l-txt small { font-size: 11px; font-weight: 700; color: var(--ink-2); }
.legend-filter {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 2px 10px; padding: 8px 12px; border-radius: 12px;
  background: var(--brand-tint); font-size: 13px; font-weight: 700; color: var(--ink-2);
}
.linklike { background: none; border: none; color: var(--brand-deep); font-weight: 800; cursor: pointer; text-decoration: underline; font-size: 13px; padding: 0; }

/* orari raggruppati per medico (P3 branca) */
.slot-group { margin-top: 14px; }
.slot-group .sg-head { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.slot-group .sg-bar { width: 4px; height: 26px; border-radius: 3px; flex-shrink: 0; }
.slot-group .sg-name { font-size: 15px; font-weight: 800; }
/* fasce prelievi */
.fascia-label { font-size: 12px; font-weight: 800; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; margin: 14px 0 8px; }
.slots-fixed { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
/* titolo giorno "appiccicato" mentre si scorre l'elenco orari */
.sticky-day { position: sticky; top: 0; background: var(--card); padding: 6px 0; z-index: 5; }
.list-sep { font-size: 12px; font-weight: 800; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; margin: 12px 4px 6px; }

/* Riprenota */
.card.riprenota { border: 1.5px solid var(--brand); background: var(--brand-tint); }
.presel-badge {
  display: flex; align-items: center; gap: 10px; margin: -6px 0 12px;
  padding: 9px 12px; border-radius: 12px; background: var(--brand-tint);
  border: 1.5px solid var(--brand); font-size: 13.5px; font-weight: 800; color: var(--ink);
}
.presel-badge .grow { flex: 1; }

/* P6 check animato */
.done-check {
  width: 76px; height: 76px; margin: 0 auto; border-radius: 50%;
  background: var(--brand-tint); color: var(--brand-deep);
  display: flex; align-items: center; justify-content: center;
  animation: pop .3s cubic-bezier(.3, 1.4, .5, 1);
}
.done-check.ok { background: #E6F4EA; color: #1E8449; }
.done-check svg { width: 40px; height: 40px; stroke-width: 2.4; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* desktop >=960px: calendario a sinistra (sticky), orari a destra */
.booking-2col { display: block; }
@media (min-width: 960px) {
  .booking-2col { display: grid; grid-template-columns: minmax(0, 460px) 1fr; gap: 22px; align-items: start; }
  .booking-2col .col-cal { position: sticky; top: 78px; }
}
@media (prefers-reduced-motion: reduce) {
  .done-check { animation: none; }
}

/* ---------------------------------------------------------------- viewer PDF */
.pdfview {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 120;
  display: flex; flex-direction: column;
  background: var(--paper);
}
.pdfview .p-bar {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--card); border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
}
.pdfview .p-bar b { flex: 1; font-size: 14.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdfview iframe { flex: 1; width: 100%; border: none; background: #525659; }

/* ---------------------------------------------------------------- ticket (firma) */
.ticket {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, var(--brand) 0%, #E07C00 78%, var(--brand-deep) 100%);
  color: #fff; border-radius: var(--r); padding: 20px;
  box-shadow: 0 10px 28px rgba(243, 146, 0, .32);
  margin-bottom: 14px;
}
.ticket::before, .ticket::after {
  content: ''; position: absolute; width: 22px; height: 22px; border-radius: 50%;
  background: var(--paper); top: 50%; margin-top: -11px;
}
.ticket::before { left: -11px; }
.ticket::after { right: -11px; }
.ticket .t-eyebrow { font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; opacity: .85; margin-bottom: 6px; }
.ticket .t-title { font-family: 'Fraunces', Georgia, serif; font-size: 21px; font-weight: 600; line-height: 1.25; }
.ticket .t-sub { font-size: 13.5px; font-weight: 600; opacity: .92; margin-top: 3px; }
.ticket .t-when {
  margin-top: 14px; padding-top: 13px;
  border-top: 1.5px dashed rgba(255, 255, 255, .45);
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}
.ticket .t-when b { font-size: 19px; font-weight: 800; }
.ticket .t-when span { font-size: 13px; font-weight: 700; opacity: .9; }
.ticket .t-actions { margin-top: 12px; display: flex; gap: 8px; }
.ticket .t-actions button {
  border: none; border-radius: 10px; padding: 8px 14px; min-height: 38px;
  background: rgba(255, 255, 255, .2); color: #fff; font-weight: 800; font-size: 13px; cursor: pointer;
}
.ticket .t-actions button:hover { background: rgba(255, 255, 255, .32); }

/* ---------------------------------------------------------------- filo arancio (timeline) */
.thread { position: relative; padding-left: 26px; }
.thread::before {
  content: ''; position: absolute; left: 8px; top: 6px; bottom: 6px;
  width: 2.5px; border-radius: 2px;
  background: linear-gradient(var(--brand), var(--brand-tint-2));
}
.thread .t-item { position: relative; padding: 0 0 18px; }
.thread .t-item::before {
  content: ''; position: absolute; left: -24px; top: 5px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--brand); border: 2.5px solid var(--paper);
  box-shadow: 0 0 0 1.5px var(--brand);
}
.thread .t-year {
  position: relative; margin: 4px 0 14px;
  font-family: 'Fraunces', Georgia, serif; font-size: 18px; font-weight: 600; color: var(--ink-2);
}
.thread .t-year::before {
  content: ''; position: absolute; left: -26px; top: 7px;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--paper); border: 2.5px solid var(--brand);
}
.t-item .t-date { font-size: 12px; font-weight: 800; color: var(--brand-deep); font-variant-numeric: tabular-nums; }
.t-item .t-name { font-size: 15px; font-weight: 800; }
.t-item .t-meta { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.t-item .t-link { margin-top: 4px; }

/* ---------------------------------------------------------------- home */
.hello { margin: 14px 0 18px; }
.hello .h-greet { font-family: 'Fraunces', Georgia, serif; font-weight: 600; font-size: 30px; letter-spacing: -0.01em; line-height: 1.1; }
.hello .h-sub { color: var(--ink-2); font-weight: 600; font-size: 14px; margin-top: 5px; }
.quick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .quick { grid-template-columns: repeat(4, 1fr); } }
.quick button {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  padding: 14px; min-height: 88px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow); cursor: pointer; text-align: left;
  font-size: 14px; font-weight: 800; color: var(--ink);
  transition: transform .12s, border-color .12s;
}
.quick button:hover { border-color: var(--brand); transform: translateY(-2px); }
.quick button svg { width: 24px; height: 24px; color: var(--brand); }
.quick button small { font-size: 11.5px; font-weight: 600; color: var(--ink-2); }

.rowitem {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 2px; border-bottom: 1px solid var(--line);
}
.rowitem:last-child { border-bottom: none; }
.rowitem .grow { flex: 1; min-width: 0; }
.rowitem b { font-size: 14.5px; display: block; }
.rowitem .sub { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.rowitem .val { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------------------------------------------------------------- auth */
.authwrap { max-width: 430px; margin: 0 auto; padding: 24px 18px 40px; }
.authhero { text-align: center; padding: 26px 0 20px; }
/* logo orizzontale (775x359): mai forzato in un quadrato, aspect ratio nativo */
.authhero img {
  width: min(250px, 72vw); height: auto;
  border-radius: 16px; background: #fff; padding: 14px 18px;
  box-shadow: var(--shadow-lg);
}
.authhero .a-title { font-family: 'Fraunces', Georgia, serif; font-size: 28px; font-weight: 600; margin-top: 14px; }
.authhero .a-sub { color: var(--ink-2); font-weight: 600; font-size: 14px; margin-top: 4px; }

.pinwrap { max-width: 330px; margin: 0 auto; }
.pindots { display: flex; justify-content: center; gap: 14px; margin: 22px 0 26px; }
.pindots i {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line-2); background: var(--card); transition: all .12s;
}
.pindots i.full { background: var(--brand); border-color: var(--brand); transform: scale(1.1); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.keypad button {
  height: 64px; border-radius: 18px; border: 1px solid var(--line);
  background: var(--card); box-shadow: var(--shadow);
  font-size: 24px; font-weight: 700; color: var(--ink); cursor: pointer;
  transition: transform .09s, background .12s;
  display: flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums;
}
.keypad button:hover { background: var(--brand-tint); }
.keypad button:active { transform: scale(.93); background: var(--brand-tint-2); }
.keypad button.fn { background: none; border: none; box-shadow: none; color: var(--ink-2); font-size: 15px; font-weight: 800; }
.keypad button.fn svg { width: 26px; height: 26px; }

/* ---------------------------------------------------------------- sheet / toast */
.sheetveil {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 90;
  background: rgba(20, 14, 8, .45); backdrop-filter: blur(2px);
  animation: fadein .18s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  position: fixed; z-index: 91; left: 0; right: 0; bottom: 0;
  max-height: 88dvh; overflow-y: auto;
  background: var(--card); border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(22px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lg);
  animation: sheetup .24s cubic-bezier(.3, 1, .4, 1);
}
@keyframes sheetup { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.sheet .grab { width: 42px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 4px auto 14px; }
@media (min-width: 960px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; transform: translate(-50%, -50%); width: 520px; border-radius: 22px; animation: fadein .18s ease; }
}

.toast {
  position: fixed; z-index: 120; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--paper);
  padding: 12px 20px; border-radius: 30px; font-size: 14px; font-weight: 700;
  box-shadow: var(--shadow-lg); max-width: 88vw; text-align: center;
  animation: toastin .22s ease;
}
@keyframes toastin { from { transform: translate(-50%, 12px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ---------------------------------------------------------------- switch */
.switchrow { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.switchrow:last-child { border-bottom: none; }
.switchrow .grow { flex: 1; }
.switchrow b { font-size: 14.5px; display: block; }
.switchrow .sub { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.switch { position: relative; width: 50px; height: 30px; flex-shrink: 0; cursor: pointer; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch i {
  position: absolute; inset: 0; border-radius: 20px;
  background: var(--line-2); transition: background .16s; pointer-events: none;
}
.switch i::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, .25); transition: transform .16s;
}
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:focus-visible + i { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------------------------------------------------------------- dl dati */
.datalist { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; font-size: 14px; }
.datalist dt { color: var(--ink-2); font-weight: 700; }
.datalist dd { font-weight: 700; overflow-wrap: anywhere; }

/* referto testo */
.refertotext {
  white-space: pre-wrap; font-size: 14.5px; line-height: 1.65;
  background: var(--card-2); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 16px; overflow-wrap: anywhere;
}
.refertohtml { white-space: normal; max-height: 56dvh; overflow-y: auto; }
.refertohtml p { margin-bottom: 8px; }
.refertohtml ul, .refertohtml ol { padding-left: 20px; margin-bottom: 8px; }
.refertohtml table { border-collapse: collapse; width: 100%; margin: 8px 0; }
.refertohtml td, .refertohtml th { border: 1px solid var(--line-2); padding: 5px 8px; font-size: 13px; }
.refertohtml h1, .refertohtml h2, .refertohtml h3, .refertohtml h4 { font-size: 15px; margin: 10px 0 6px; }

/* skeleton */
.skel { border-radius: 10px; background: linear-gradient(90deg, var(--card-2) 25%, var(--brand-tint) 50%, var(--card-2) 75%); background-size: 200% 100%; animation: skel 1.1s linear infinite; min-height: 18px; margin-bottom: 8px; }
@keyframes skel { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* stagger di ingresso vista */
.view-enter > * { animation: rise .3s ease both; }
.view-enter > *:nth-child(2) { animation-delay: .04s; }
.view-enter > *:nth-child(3) { animation-delay: .08s; }
.view-enter > *:nth-child(4) { animation-delay: .12s; }
.view-enter > *:nth-child(5) { animation-delay: .16s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* stampa (dettaglio fattura) */
@media print {
  .topbar, .bottomnav, .sidebar, .noprint, .toast { display: none !important; }
  body { background: #fff; color: #000; }
  .card, .sheet { box-shadow: none; border: none; }
  .sheet { position: static; transform: none; width: auto; max-height: none; }
  .sheetveil { display: none; }
  /* con una sheet aperta (dettaglio fattura) si stampa SOLO la sheet,
     non la lista sottostante */
  body.has-sheet #app { display: none !important; }
}
