/* TYFamily — Template C (scuro) con barra del Template A. Token da §19.2 del Documento Unico. */
:root {
  --bg: #071523;
  --surface: #102238;
  --surface-2: #17304d;
  --text: #f5f7fa;
  --text-2: #b7c3d1;
  --accent: #087df2;
  --accent-text: #6cb4ff;   /* azzurro schiarito: contrasto sufficiente come testo su fondo scuro */
  --yellow: #ffcc22;
  --green: #07834a;
  --red: #d9282f;
  --tabs-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabs-h) + var(--safe-b));
  padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px);
}
h1, h2, h3, p { margin: 0; }
h2 { font-size: 1.5rem; font-weight: 700; text-wrap: balance; }
h3 { font-size: 1rem; margin-top: 20px; margin-bottom: 8px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.muted { color: var(--text-2); }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); color: var(--text); padding: 12px 16px; z-index: 30; }
.skip:focus { left: 8px; top: calc(8px + var(--safe-t)); }

.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 16px 10px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 1.25rem; font-weight: 700; letter-spacing: 0.01em; }
.brand img { border-radius: 7px; }
.avatar { width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; background: transparent; display: grid; place-content: center; cursor: pointer; }

.top-actions { display: flex; align-items: center; gap: 6px; }
.upload-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 16px 0 12px; border: 0; border-radius: 22px;
  background: var(--accent); color: #fff; font: inherit; font-weight: 700; cursor: pointer; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.upload-btn:active { transform: translateY(1px); }
.upload-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.upload-btn.busy { animation: up-pulse 1.6s ease-in-out infinite; }
@keyframes up-pulse { 50% { opacity: 0.6; } }
@media (prefers-reduced-motion: reduce) { .upload-btn.busy { animation: none; } }
.news-btn { position: relative; display: grid; place-content: center; }
.news-btn svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.news-btn .count { position: absolute; top: 2px; right: 0; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--red); color: #fff; font-size: 0.75rem; font-weight: 700; line-height: 20px; text-align: center; box-shadow: 0 0 0 2px var(--bg); }
.avatar { position: relative; }
.avatar.pending::after { content: ''; position: absolute; top: 2px; right: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--yellow); box-shadow: 0 0 0 2px var(--bg); }
.btn.wa { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; background: #128c4b; border-color: #128c4b; color: #fff; }
.wa-preview { white-space: pre-wrap; background: var(--surface); border-radius: 12px; padding: 12px; margin: 8px 0 12px; overflow-wrap: anywhere; }
@media (max-width: 420px) { .upload-btn { padding: 0 12px 0 10px; } .top { padding-left: 12px; padding-right: 12px; } .brand { font-size: 1.1rem; } }
/* ------------------------------------------------------------ presentazione a tutto schermo */
.show { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; border-radius: 0; background: #000; overflow: hidden; color: #fff; }
.show::backdrop { background: #000; }
.show-stage { position: absolute; inset: 0; }
.show-item { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; animation: show-in 0.9s ease both; }
@keyframes show-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .show-item { animation: none; } }
.show-caption { position: absolute; left: 0; right: 0; bottom: 0; padding: 40px 4vw calc(18px + var(--safe-b)); font-size: clamp(1rem, 2.2vw, 1.8rem); font-weight: 600; text-shadow: 0 1px 6px #000; background: linear-gradient(transparent, rgba(0, 0, 0, 0.6)); pointer-events: none; }
.show-note { position: absolute; top: 5vh; left: 50%; transform: translateX(-50%); max-width: 86vw; padding: 10px 20px; border-radius: 14px; background: rgba(0, 0, 0, 0.7); font-size: clamp(0.95rem, 1.8vw, 1.5rem); opacity: 0; transition: opacity 0.3s; pointer-events: none; text-align: center; }
.show-note.on { opacity: 1; }
.show-hint { display: none; }
.show-close, .show-music { position: absolute; top: calc(10px + var(--safe-t)); background: rgba(0, 0, 0, 0.45); color: #fff; opacity: 0.55; }
.show-close { right: 12px; }
.show-music { right: 64px; }
.show-close:hover, .show-music:hover, .show-close:focus-visible, .show-music:focus-visible { opacity: 1; }
.show-btn { background: var(--surface); }

/* ------------------------------------------------------------ modalità TV: si legge dal divano, si guida con le frecce */
html.tv { font-size: 125%; }
html.tv :focus, html.tv :focus-visible { outline: 5px solid var(--yellow); outline-offset: 4px; border-radius: 10px; }
html.tv main { max-width: 94vw; padding-left: 3vw; padding-right: 3vw; }
html.tv .upload-btn, html.tv .install-card { display: none; }
html.tv .show-close, html.tv .show-music { display: none; }

/* Schermata di una TV non ancora collegata: QR grande e codice leggibile da lontano. */
.pair { min-height: 78vh; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 5vw; padding: 4vh 2vw; }
.pair-qr { flex: none; width: min(40vh, 80vw); padding: 12px; background: #fff; border-radius: 18px; }
.pair .qr { display: block; width: 100%; height: auto; }
.pair-text { max-width: 34em; }
.pair-text h2 { font-size: 2rem; margin-bottom: 0.6em; }
.pair-text ol { margin: 0 0 1em 1.2em; padding: 0; display: grid; gap: 0.5em; font-size: 1.15rem; }
.pair-code { font-size: 3rem; font-weight: 800; letter-spacing: 0.12em; font-variant-numeric: tabular-nums; margin-top: 0.2em; }
.pair-input { font-size: 1.4rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }
.crop-box { display: grid; place-content: center; margin: 8px 0 12px; }
.crop-view { width: min(280px, 72vw); height: min(280px, 72vw); border-radius: 50%; background: var(--surface); box-shadow: 0 0 0 3px var(--accent); touch-action: none; cursor: grab; }
.crop-view:active { cursor: grabbing; }
.crop-zoom { width: 100%; min-height: 44px; accent-color: var(--accent); }
.up-list { max-height: 38vh; overflow-y: auto; margin-top: 8px; }
.up-list li { display: grid; grid-template-columns: 1fr; gap: 4px; justify-content: stretch; }
.up-list .up-name { overflow-wrap: anywhere; }
.up-list progress { width: 100%; height: 8px; accent-color: var(--accent); }
#sheet details { margin-top: 12px; }
#sheet summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; color: var(--text-2); }

/* Immagine tonda di una persona: ritaglio sul volto, miniatura, oppure iniziale. */
.face { position: relative; display: inline-grid; flex: none; width: 84px; height: 84px; border-radius: 50%; overflow: hidden; background: var(--surface); box-shadow: 0 0 0 2px var(--surface-2); }
.face img { width: 100%; height: 100%; object-fit: cover; display: block; }
.face img.crop { position: absolute; max-width: none; object-fit: fill; opacity: 0; transition: opacity 0.2s; }
.face.ready img.crop { opacity: 1; }
.face.initial { place-content: center; background: linear-gradient(135deg, var(--accent), #0f6a5a); color: #fff; font-weight: 700; font-size: 1.9rem; }
.face.small { width: 40px; height: 40px; }
.face.small.initial { font-size: 1.05rem; }
@media (prefers-reduced-motion: reduce) { .face img.crop { transition: none; } }

main { max-width: 1100px; margin: 0 auto; padding: 8px 16px 24px; outline: none; }
.view > h2 { margin: 20px 0 8px; }
.empty { color: var(--text-2); max-width: 46ch; padding: 8px 0 32px; }


.card { background: var(--surface); border-radius: 14px; padding: 16px; margin-top: 16px; }
.card h2 { font-size: 1.1rem; margin-bottom: 4px; }
.card p { color: var(--text-2); margin-bottom: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 20px; }

.btn {
  min-height: 44px; padding: 0 16px; border-radius: 22px; border: 1px solid var(--surface-2);
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.quiet { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.link { display: inline-grid; place-content: center; text-decoration: none; }
.btn:active { transform: translateY(1px); }

.state.message { text-align: center; padding: 15vh 8px 0; display: grid; gap: 12px; justify-items: center; }
.state.message p { color: var(--text-2); max-width: 40ch; }

.skeleton { background: var(--surface); border-radius: 10px; animation: pulse 1.4s ease-in-out infinite; }
.skeleton-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-top: 8px; }
.skeleton-grid .skeleton { aspect-ratio: 1; border-radius: 4px; }
@keyframes pulse { 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } .btn:active { transform: none; } }

.banner {
  display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between;
  margin: 0 16px 8px; padding: 10px 14px; border-radius: 12px; background: var(--surface); border-left: 4px solid var(--yellow);
}

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 0 env(safe-area-inset-right, 0px) var(--safe-b) env(safe-area-inset-left, 0px);
  background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(12px); border-top: 1px solid var(--surface-2);
}
.tabs a {
  min-height: var(--tabs-h); display: grid; place-content: center; justify-items: center; gap: 2px;
  color: var(--text-2); text-decoration: none; font-size: 0.72rem; font-weight: 600;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current="page"] { color: var(--accent-text); }

dialog {
  width: min(92vw, 460px); border: 0; border-radius: 18px; padding: 22px; background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(3, 10, 18, 0.7); }
dialog ol { margin: 0; padding-left: 1.2em; color: var(--text-2); display: grid; gap: 6px; }
dialog ol strong { color: var(--text); }

@media (min-width: 760px) {
  .skeleton-grid { grid-template-columns: repeat(6, 1fr); }
  main { padding-left: 24px; padding-right: 24px; }
}

/* ------------------------------------------------------------ Fase 3: catalogo */
a { color: var(--accent-text); }
.brand a { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; }
.center { text-align: center; }
.note { margin-top: 20px; max-width: 60ch; font-size: 0.9rem; }
.warn { color: var(--yellow); }
.view-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin: 20px 0 10px; }
.view-head h2 { margin: 0; }
.back { display: inline-block; margin-top: 10px; min-height: 44px; line-height: 44px; text-decoration: none; font-weight: 600; }
.section-title { margin: 24px 0 8px; font-size: 1.05rem; color: var(--text-2); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 36px; padding: 0 14px; display: inline-grid; place-content: center; border-radius: 18px; background: var(--surface); color: var(--text); text-decoration: none; font-weight: 600; font-size: 0.92rem; }
.chip.on { background: var(--accent); color: #fff; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 3px; }
.day { content-visibility: auto; contain-intrinsic-size: auto 320px; }
.day-title { margin: 18px 0 8px; font-size: 0.95rem; font-weight: 600; color: var(--text-2); }
.tile { position: relative; aspect-ratio: 1; padding: 0; border: 0; border-radius: 4px; overflow: hidden; background: var(--surface); cursor: pointer; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.broken img { visibility: hidden; }
.tile.broken::after { content: attr(data-msg); position: absolute; inset: 0; display: grid; place-content: center; padding: 6px; text-align: center; font-size: 0.7rem; color: var(--text-2); }
.badge-video { position: absolute; left: 5px; bottom: 5px; padding: 1px 6px; border-radius: 9px; background: rgba(3, 10, 18, 0.72); color: #fff; font-size: 0.72rem; font-weight: 600; }
.dot { position: absolute; right: 5px; top: 5px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid rgba(3, 10, 18, 0.8); background: var(--text-2); }
.dot.in_review { background: var(--yellow); }
.dot.rejected { background: var(--red); }
.sentinel { height: 1px; }

.strip { margin-top: 18px; }
.strip-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.strip-head h2 { font-size: 1.15rem; }
.strip-head a { text-decoration: none; font-weight: 600; white-space: nowrap; }
.strip-row { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 6px; scroll-snap-type: x proximity; }
.strip-row > * { flex: 0 0 auto; scroll-snap-align: start; }
.strip-row .tile { width: 112px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.card-event { display: block; border-radius: 14px; overflow: hidden; background: var(--surface); color: var(--text); text-decoration: none; }
.card-event img, .card-event .no-cover { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; }
.no-cover { background: linear-gradient(120deg, #0b3a6b, #0f6a5a); }
.card-event .card-body { display: grid; gap: 3px; padding: 10px 12px 12px; }
.card-event.compact { width: 168px; }
.card-event.compact img, .card-event.compact .no-cover { aspect-ratio: 4 / 3; }
.card-event.compact strong { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 0.92rem; }
.card-event.compact .muted { font-size: 0.78rem; }
.chip-state { display: inline-block; margin-right: 6px; padding: 1px 8px; border-radius: 9px; font-size: 0.75rem; font-weight: 700; background: var(--surface-2); color: var(--text-2); justify-self: start; }
.chip-state.published { background: var(--green); color: #fff; }
.chip-state.in_review { background: var(--yellow); color: #1b1300; }
.chip-state.rejected { background: var(--red); color: #fff; }

.buckets { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.bucket { position: relative; display: block; aspect-ratio: 4 / 3; border-radius: 12px; overflow: hidden; background: var(--surface); color: #fff; text-decoration: none; }
.bucket img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bucket-label { position: absolute; inset: auto 0 0 0; display: grid; padding: 22px 10px 8px; background: linear-gradient(transparent, rgba(3, 10, 18, 0.88)); font-size: 0.82rem; }
/* I nomi lunghi (certi comuni) non devono coprire la foto: al massimo due righe. */
.bucket-label strong { font-size: 1rem; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }

.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 18px 10px; }
.person { display: grid; justify-items: center; gap: 3px; text-align: center; color: var(--text); text-decoration: none; font-size: 0.9rem; }
.person strong { overflow-wrap: anywhere; }
.person-head { display: flex; align-items: center; gap: 14px; margin: 14px 0 12px; }
.profile { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.profile #account-name { font-size: 1.15rem; font-weight: 700; }
.user-row { display: flex; align-items: center; gap: 10px; }
.field { display: grid; gap: 4px; }
.field .search { margin-bottom: 8px; }
button.chip { border: 0; font: inherit; font-weight: 600; font-size: 0.92rem; cursor: pointer; }

.search { width: 100%; min-height: 46px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--surface-2); background: var(--surface); color: var(--text); font: inherit; margin-bottom: 10px; }
select.search { appearance: auto; }

.admin-actions { margin: 12px 0 4px; }
.card h3 { margin-top: 0; }
.rows { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 2px; }
.rows li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--surface-2); }
.rows li > a, .rows li > span:first-child { flex: 1 1 220px; color: var(--text); text-decoration: none; }
.options { border: 0; margin: 0 0 8px; padding: 0; display: grid; gap: 4px; }
.option { display: flex; gap: 10px; align-items: flex-start; min-height: 44px; padding: 8px 4px; cursor: pointer; }
.option input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.option span { display: grid; }
.checks { max-height: 34vh; overflow-y: auto; padding-left: 8px; border-left: 2px solid var(--surface-2); margin-bottom: 8px; }
.impact { min-height: 2.9em; margin-top: 8px; font-weight: 600; }
#sheet h2 { font-size: 1.2rem; margin-bottom: 12px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--tabs-h) + var(--safe-b) + 14px); transform: translateX(-50%); z-index: 60; max-width: min(92vw, 520px); padding: 10px 16px; border-radius: 12px; background: var(--surface-2); color: var(--text); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5); }

/* ------------------------------------------------------------ visualizzatore */
.viewer { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border-radius: 0; background: #02070d; overflow: hidden; }
.viewer[open] { display: grid; grid-template-rows: auto 1fr; }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: calc(6px + var(--safe-t)) 8px 6px; }
.viewer-title { flex: 1; text-align: center; font-weight: 600; font-size: 0.95rem; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; color: var(--text); font-size: 1.25rem; cursor: pointer; }
.icon-btn:hover { background: var(--surface); }
.viewer-stage { min-height: 0; display: grid; place-items: center; padding-bottom: var(--safe-b); }
.viewer-stage img, .viewer-stage video { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; }
.viewer-stage img.loading { filter: blur(6px); transform: scale(1.02); }
.viewer-stage video { width: 100%; height: 100%; background: #000; }
.viewer-msg { max-width: 34ch; text-align: center; display: grid; gap: 10px; justify-items: center; padding: 16px; }
.viewer-nav { position: absolute; top: 50%; width: 48px; height: 72px; margin-top: -36px; border: 0; background: rgba(3, 10, 18, 0.45); color: #fff; font-size: 2rem; cursor: pointer; }
.viewer-nav.prev { left: 0; border-radius: 0 12px 12px 0; }
.viewer-nav.next { right: 0; border-radius: 12px 0 0 12px; }
.viewer-info { position: absolute; left: 0; right: 0; bottom: 0; max-height: 62dvh; overflow-y: auto; padding: 16px 16px calc(16px + var(--safe-b)); background: var(--surface); border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.5); }
.viewer-info dl { margin: 0; display: grid; gap: 10px; }
.info-row { display: grid; grid-template-columns: 9.5em 1fr; gap: 8px; }
.info-row dt { color: var(--text-2); }
.info-row dd { margin: 0; overflow-wrap: anywhere; }
.info-admin { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--surface-2); display: grid; gap: 10px; }
@media (hover: none) { .viewer-nav { display: none; } }
@media (min-width: 900px) {
  .viewer.with-info[open] { grid-template-columns: 1fr 360px; }
  .viewer.with-info .viewer-bar { grid-column: 1 / -1; }
  .viewer-info { position: static; max-height: none; border-radius: 0; box-shadow: none; }
  .viewer.with-info .viewer-nav.next { right: 360px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
@media (max-width: 420px) { .info-row { grid-template-columns: 1fr; gap: 0; } }
