/* Presepe 2C — "mostra serale": blu notte, avorio, luce di candela */
:root {
  --bg: #141a2e;
  --surface: #1b2239;
  --raised: #242c47;
  --line: rgba(236, 228, 214, .12);
  --line-strong: rgba(236, 228, 214, .22);
  --text: #ece4d6;
  --muted: #a8a296;
  --candle: #e3b05c;
  --candle-deep: #b9852f;
  --sage: #93ad8c;
  --brick: #d76a52;

  /* nomi usati anche nel JavaScript */
  --ink: var(--text);
  --ink-soft: var(--muted);
  --red: var(--brick);
  --green: var(--sage);
  --gold-deep: var(--candle);
  --paper: var(--surface);

  --serif: 'Instrument Serif', 'Iowan Old Style', Georgia, serif;
  --sans: 'Hanken Grotesk', system-ui, sans-serif;
  --r: 6px;
  --r-lg: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background:
    radial-gradient(1200px 360px at 50% -160px, rgba(227, 176, 92, .08), transparent 75%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
img { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--candle); }
:focus-visible { outline: 2px solid var(--candle); outline-offset: 2px; }
::selection { background: var(--candle); color: var(--bg); }


h1, h2, h3 { font-family: var(--serif); font-weight: 400; margin: 0; line-height: 1.05; letter-spacing: -.01em; }
h1 { font-size: clamp(2.5rem, 6vw, 3.8rem); }
h2 { font-size: 1.9rem; }
h3 { font-size: 1.45rem; }
code { font-size: .92em; color: var(--candle); }

/* ---------- barra in alto ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 32px;
  padding: 0 28px; height: 64px;
  background: rgba(20, 26, 46, .88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none;
  font-family: var(--serif); font-size: 1.5rem; white-space: nowrap;
}
.nav { display: flex; gap: 26px; flex: 1; height: 100%; }
.nav a {
  display: flex; align-items: center; height: 100%;
  color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color .15s;
}
.nav a:hover { color: var(--text); }
.nav a.active { color: var(--text); border-bottom-color: var(--candle); }
.who { display: flex; align-items: center; gap: 14px; color: var(--muted); white-space: nowrap; font-size: .95rem; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 12px 16px 0; gap: 0 12px; }
  .who { margin-left: auto; }
  #who-name { display: none; }
  .nav { order: 3; flex: 0 0 100%; height: 44px; gap: 22px; overflow-x: auto; scrollbar-width: none; }
}

/* ---------- layout ---------- */
main { max-width: 1120px; margin: 0 auto; padding: 48px 28px 96px; }
@media (max-width: 760px) { main { padding: 28px 16px 72px; } }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap;
  margin-bottom: 36px; padding-bottom: 28px; border-bottom: 1px solid var(--line);
}
.sub { color: var(--muted); margin: 12px 0 0; max-width: 58ch; font-size: 1.05rem; }

/* indicatore delle fasi: è davvero una sequenza */
.steps {
  list-style: none; margin: 0 0 18px; padding: 0;
  display: flex; gap: 0; counter-reset: s; font-size: .9rem;
}
.steps li {
  counter-increment: s;
  display: flex; align-items: center; gap: 8px;
  color: var(--muted);
}
.steps li::before {
  content: counter(s);
  display: grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--line-strong); font-size: .75rem; font-weight: 600;
}
.steps li + li { margin-left: 10px; }
.steps li:not(:last-child)::after {
  content: ''; width: 28px; height: 1px; background: var(--line-strong); margin-left: 4px;
}
.steps li.done { color: var(--text); }
.steps li.done::before { content: '✓'; border-color: var(--sage); color: var(--sage); }
.steps li.now { color: var(--candle); font-weight: 600; }
.steps li.now::before { background: var(--candle); border-color: var(--candle); color: var(--bg); }
@media (max-width: 420px) { .steps li:not(:last-child)::after { width: 12px; } }

/* ---------- bottoni e campi ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--candle); cursor: pointer;
  padding: 11px 22px; border-radius: var(--r);
  background: var(--candle); color: #1d1608; font-weight: 600;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #ecc073; border-color: #ecc073; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.big { padding: 13px 26px; font-size: 1.05rem; }
.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line-strong); background: transparent; color: var(--text);
  padding: 10px 18px; border-radius: var(--r); cursor: pointer; font-weight: 500;
  transition: border-color .15s, background .15s;
}
.btn-ghost:hover { border-color: var(--text); }
.btn-ghost.danger { color: var(--brick); border-color: rgba(215, 106, 82, .4); }
.btn-ghost.danger:hover { border-color: var(--brick); }
.small { padding: 6px 12px; font-size: .88rem; }

label.field { display: block; margin-bottom: 16px; }
label.field > span, .field > span { display: block; font-weight: 500; font-size: .9rem; margin-bottom: 6px; color: var(--muted); }
.input {
  width: 100%; padding: 11px 13px;
  border: 1px solid var(--line-strong); border-radius: var(--r);
  background: rgba(0, 0, 0, .18); color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: rgba(168, 162, 150, .6); }
.input:focus { border-color: var(--candle); box-shadow: 0 0 0 3px rgba(227, 176, 92, .18); }
textarea.input { min-height: 150px; resize: vertical; line-height: 1.55; }
select.input option { background: var(--surface); }

/* ---------- login ---------- */
.login-wrap {
  min-height: calc(100vh - 96px);
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 64px; align-items: center;
}
.login-title { font-size: clamp(3.2rem, 8vw, 6rem); line-height: .95; }
.login-intro p { color: var(--muted); font-size: 1.15rem; max-width: 34ch; margin: 24px 0 0; }
.login-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 36px 32px 32px;
}
.login-card h2 { margin-bottom: 22px; }
.login-card .btn { width: 100%; margin-top: 4px; }
.form-error { color: var(--brick); font-weight: 500; min-height: 1.4em; margin: 4px 0 8px; white-space: pre-line; }
@media (max-width: 820px) {
  .login-wrap { grid-template-columns: 1fr; gap: 36px; min-height: 0; padding-top: 12px; }
}

/* ---------- idee: una galleria ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 44px 32px; }
.idea-card {
  display: flex; flex-direction: column; gap: 14px;
  border: 0; padding: 0; background: none; text-align: left; cursor: pointer; color: inherit;
}
.idea-cover {
  aspect-ratio: 4 / 3; border-radius: var(--r); overflow: hidden; position: relative;
  background: var(--surface); border: 1px solid var(--line);
}
.idea-cover img { width: 100%; height: 100%; object-fit: cover; transition: transform .5s ease, filter .3s; filter: saturate(.92); }
.idea-card:hover .idea-cover img { transform: scale(1.03); filter: saturate(1); }
.idea-cover .no-photo { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: .9rem; }
.photo-count, .mine-badge {
  position: absolute; bottom: 10px; font-size: .78rem; font-weight: 600;
  padding: 3px 9px; border-radius: 4px; background: rgba(20, 26, 46, .82); color: var(--text);
}
.photo-count { right: 10px; }
.mine-badge { left: 10px; color: var(--candle); }
.idea-body { display: flex; flex-direction: column; gap: 4px; }
.idea-body h3 { font-size: 1.7rem; }
.idea-card:hover h3 { color: var(--candle); }
.idea-body .by { color: var(--muted); font-size: .9rem; }
.idea-body p {
  margin: 6px 0 0; color: #cfc8ba; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.empty { padding: 56px 24px; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: var(--r-lg); text-align: center; }

/* ---------- finestre ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(8, 11, 22, .75); backdrop-filter: blur(3px); animation: fade .2s; }
.modal-card {
  position: relative; width: min(760px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 34px; box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
  animation: rise-in .25s ease-out;
}
.modal-x {
  position: absolute; right: 14px; top: 14px; z-index: 2;
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text); font-size: 1.3rem; cursor: pointer; line-height: 1;
}
.modal-x:hover { border-color: var(--text); }
.modal-card h2 { font-size: 2.3rem; margin-bottom: 6px; padding-right: 44px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 22px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(12px); } }
@media (max-width: 560px) { .modal-card { padding: 26px 18px; } .modal-card h2 { font-size: 1.9rem; } }

.gallery { margin: 20px 0; }
.gallery-main { border-radius: var(--r); overflow: hidden; aspect-ratio: 4 / 3; background: #0c101d; }
.gallery-main img { width: 100%; height: 100%; object-fit: contain; }
.thumbs { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; }
.thumbs button { border: 2px solid transparent; padding: 0; border-radius: 4px; overflow: hidden; cursor: pointer; flex: 0 0 76px; height: 57px; background: none; opacity: .6; }
.thumbs button.on { border-color: var(--candle); opacity: 1; }
.thumbs img { width: 100%; height: 100%; object-fit: cover; }
.idea-desc { white-space: pre-wrap; line-height: 1.65; color: #d9d2c4; max-width: 68ch; }

.photo-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.photo-slot { position: relative; aspect-ratio: 1; border-radius: var(--r); overflow: hidden; background: var(--raised); }
.photo-slot img { width: 100%; height: 100%; object-fit: cover; }
.photo-slot .rm {
  position: absolute; top: 5px; right: 5px; width: 26px; height: 26px; border-radius: 50%;
  border: 0; background: rgba(10, 13, 25, .8); color: #fff; cursor: pointer; font-size: 1rem; line-height: 1;
}
.photo-add {
  aspect-ratio: 1; border-radius: var(--r); border: 1px dashed var(--line-strong);
  display: grid; place-items: center; text-align: center; padding: 8px;
  color: var(--muted); font-size: .85rem; cursor: pointer;
}
.photo-add:hover { border-color: var(--candle); color: var(--candle); }
.photo-add input { display: none; }

/* ---------- votazione ---------- */
.podium-slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin-bottom: 32px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.slot { padding: 18px 20px; background: var(--bg); display: flex; flex-direction: column; gap: 4px; min-height: 104px; }
.slot .pts { font-family: var(--serif); font-size: 2.4rem; line-height: 1; color: var(--muted); }
.slot .pts small { font-family: var(--sans); font-size: .85rem; margin-left: 6px; }
.slot.filled .pts { color: var(--candle); }
.slot .slot-title { font-weight: 600; }
.slot .slot-empty { color: var(--muted); font-size: .92rem; }
@media (max-width: 640px) {
  .podium-slots { grid-template-columns: 1fr; }
  .slot { min-height: 0; flex-direction: row; align-items: baseline; gap: 14px; padding: 14px 16px; }
  .slot .pts { font-size: 1.8rem; }
}

.vote-list { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.vote-row {
  display: flex; align-items: center; gap: 18px;
  padding: 14px 4px; border-bottom: 1px solid var(--line);
}
.vote-row.picked .vote-info b { color: var(--candle); }
.vote-thumb { width: 96px; height: 72px; border-radius: 4px; overflow: hidden; flex: 0 0 auto; background: var(--surface); cursor: pointer; border: 0; padding: 0; }
.vote-thumb img { width: 100%; height: 100%; object-fit: cover; }
.vote-info { flex: 1; min-width: 0; }
.vote-info b { display: block; font-family: var(--serif); font-weight: 400; font-size: 1.45rem; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vote-info span { color: var(--muted); font-size: .88rem; }
.pt-buttons { display: flex; gap: 6px; }
.pt-btn {
  width: 44px; height: 44px; border-radius: var(--r);
  border: 1px solid var(--line-strong); background: transparent; color: var(--text);
  font-weight: 600; font-size: 1rem; cursor: pointer; transition: background .12s, border-color .12s;
}
.pt-btn:hover { border-color: var(--candle); }
.pt-btn.on { background: var(--candle); border-color: var(--candle); color: #1d1608; }
@media (max-width: 560px) {
  .vote-row { flex-wrap: wrap; gap: 12px; }
  .vote-thumb { width: 72px; height: 54px; }
  .pt-buttons { width: 100%; justify-content: flex-end; }
  .vote-bar { padding: 10px 10px 10px 16px; border-radius: var(--r); }
  .vote-bar span { font-size: .88rem; flex: 1 1 140px; }
}
.vote-bar {
  position: sticky; bottom: 16px; margin-top: 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 12px 12px 20px; border-radius: var(--r-lg);
  background: rgba(36, 44, 71, .95); backdrop-filter: blur(8px);
  border: 1px solid var(--line-strong); box-shadow: 0 16px 40px rgba(0, 0, 0, .4);
}
.vote-bar span { color: var(--muted); }

/* ---------- risultati: il regalo e il podio ---------- */
.reveal { display: flex; flex-direction: column; align-items: center; text-align: center; }
.reveal .steps { justify-content: center; }
.reveal h1 { font-size: clamp(2.6rem, 7vw, 4.6rem); max-width: 16ch; }
.reveal .sub { margin-left: auto; margin-right: auto; }
.gift-stage { position: relative; height: 330px; width: 100%; display: grid; place-items: end center; margin: 18px 0 10px; }
.gift {
  position: relative; width: 200px; height: 220px; cursor: pointer;
  border: 0; background: none; padding: 0;
  animation: nudge 3.2s ease-in-out infinite; transform-origin: 50% 100%;
}
.gift:focus-visible { outline: 2px solid var(--candle); outline-offset: 10px; border-radius: 8px; }
.gift::after { /* ombra a terra */
  content: ''; position: absolute; left: 0; right: 0; bottom: -14px; height: 20px;
  background: radial-gradient(closest-side, rgba(0, 0, 0, .45), transparent);
}
.gift-box {
  position: absolute; bottom: 0; left: 12px; right: 12px; height: 150px; border-radius: 3px;
  background:
    linear-gradient(90deg, transparent 44%, #d9a95a 44%, #f0cf8a 50%, #d9a95a 56%, transparent 56%),
    linear-gradient(180deg, #8a2830, #5e1820);
  box-shadow: inset 0 -24px 30px rgba(0, 0, 0, .25);
}
.gift-lid {
  position: absolute; bottom: 146px; left: 0; right: 0; height: 40px; border-radius: 3px;
  background:
    linear-gradient(90deg, transparent 44%, #d9a95a 44%, #f0cf8a 50%, #d9a95a 56%, transparent 56%),
    linear-gradient(180deg, #a1323b, #7a222a);
  box-shadow: 0 6px 10px rgba(0, 0, 0, .3);
  transition: transform 1s cubic-bezier(.25, 1.3, .5, 1), opacity 1s;
}
.gift-bow { position: absolute; bottom: 36px; left: 50%; width: 96px; height: 42px; transform: translateX(-50%); }
.gift-bow::before, .gift-bow::after {
  content: ''; position: absolute; bottom: 0; width: 46px; height: 36px;
  border: 8px solid #d9a95a; border-radius: 50% 50% 8% 50%;
}
.gift-bow::before { left: 0; transform: rotate(-14deg); }
.gift-bow::after { right: 0; transform: scaleX(-1) rotate(-14deg); }
.gift-tag {
  position: absolute; bottom: 64px; right: -22px; transform: rotate(9deg);
  background: var(--text); color: #2a2318; font-family: var(--serif); font-size: 1.05rem;
  padding: 4px 12px 5px; border-radius: 2px; box-shadow: 0 4px 10px rgba(0, 0, 0, .3);
}
@keyframes nudge {
  0%, 82%, 100% { transform: rotate(0); }
  86% { transform: rotate(-2.5deg); }
  90% { transform: rotate(2.5deg); }
  94% { transform: rotate(-1deg); }
}
.gift.shaking { animation: shake .55s linear 2; }
@keyframes shake {
  0%, 100% { transform: translateX(0) rotate(0); }
  25% { transform: translateX(-6px) rotate(-3deg); }
  75% { transform: translateX(6px) rotate(3deg); }
}
.gift.open { animation: none; }
.gift.open .gift-lid { transform: translateY(-260px) rotate(-22deg); opacity: 0; }
.gift.open .gift-box { animation: sink .7s .45s ease-in forwards; }
.gift.open::after { animation: sink .7s .45s ease-in forwards; }
@keyframes sink { to { transform: scale(.7) translateY(60px); opacity: 0; } }
.burst {
  position: absolute; left: 50%; bottom: 110px; width: 8px; height: 8px; border-radius: 50%;
  transform: translate(-50%, 50%);
  box-shadow: 0 0 0 0 rgba(240, 207, 138, .8);
  animation: burst 1.1s ease-out forwards;
}
@keyframes burst { to { box-shadow: 0 0 0 300px rgba(240, 207, 138, 0); } }

.podium { display: flex; align-items: flex-end; justify-content: center; gap: 18px; width: 100%; max-width: 820px; margin: 0 auto; }
.podium-place { flex: 1; max-width: 250px; display: flex; flex-direction: column; align-items: center; }
.podium-card {
  width: 100%; text-align: left; margin-bottom: 14px;
  opacity: 0; transform: translateY(-24px);
  animation: settle .7s cubic-bezier(.2, 1.2, .4, 1) forwards;
}
.podium-card .pc-img { aspect-ratio: 4 / 3; border-radius: var(--r); overflow: hidden; background: var(--surface); border: 1px solid var(--line); }
.podium-card .pc-img img { width: 100%; height: 100%; object-fit: cover; }
.podium-card .pc-body { padding: 10px 2px 0; }
.podium-card b { display: block; font-family: var(--serif); font-weight: 400; font-size: 1.35rem; line-height: 1.1; }
.podium-card span { font-size: .85rem; color: var(--muted); }
.podium-card .pts-tag { display: inline-block; margin-top: 4px; color: var(--candle); font-weight: 600; font-size: .9rem; }
.place-1 .podium-card .pc-img { border: 2px solid var(--candle); box-shadow: 0 0 50px rgba(227, 176, 92, .35); }
.podium-block {
  width: 100%; height: 0; border-radius: 3px 3px 0 0;
  display: flex; justify-content: center; padding-top: 10px;
  font-family: var(--serif); font-size: 3rem; line-height: 1; color: rgba(20, 26, 46, .55);
  animation: grow .9s cubic-bezier(.2, .9, .3, 1) forwards;
}
.place-1 .podium-block { background: linear-gradient(180deg, #e9bd6c, #a8782c); --h: 180px; }
.place-2 .podium-block { background: linear-gradient(180deg, #b9bfcc, #747b8c); --h: 130px; }
.place-3 .podium-block { background: linear-gradient(180deg, #c18a5f, #7f5232); --h: 92px; }
@keyframes grow { to { height: var(--h); } }
@keyframes settle { to { opacity: 1; transform: none; } }
@media (max-width: 560px) {
  .podium { gap: 8px; }
  .podium-card b { font-size: 1.05rem; }
  .podium-block { font-size: 2.2rem; }
  .place-1 .podium-block { --h: 130px; } .place-2 .podium-block { --h: 92px; } .place-3 .podium-block { --h: 64px; }
}

.ranking { width: 100%; max-width: 820px; margin: 56px auto 0; text-align: left; opacity: 0; animation: settle .6s 2.6s forwards; }
.ranking h2 { margin-bottom: 14px; }
.rank-row { display: flex; align-items: center; gap: 18px; padding: 14px 0; border-top: 1px solid var(--line); }
.rank-row .n { font-family: var(--serif); font-size: 1.6rem; color: var(--muted); width: 32px; }
.rank-row:first-of-type .n { color: var(--candle); }
.rank-row .t { flex: 1; min-width: 0; }
.rank-row .t b { display: block; font-weight: 600; }
.rank-row .t span { color: var(--muted); font-size: .88rem; }
.rank-row .p { font-weight: 600; white-space: nowrap; }
.bar { height: 3px; background: var(--line); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--candle); }

/* polvere d'oro */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
#confetti i {
  position: absolute; top: -10px; border-radius: 50%;
  box-shadow: 0 0 6px rgba(240, 207, 138, .6);
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translate3d(var(--dx), 110vh, 0) rotate(var(--rot)); } }

/* ---------- ruoli ---------- */
.roles-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; }
.role-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 22px; display: flex; flex-direction: column; gap: 14px;
}
.role-top { display: flex; gap: 14px; align-items: flex-start; }
.role-emoji {
  width: 48px; height: 48px; flex: 0 0 auto; display: grid; place-items: center;
  font-family: var(--serif); font-size: 1.9rem; color: var(--candle);
  border: 1px solid rgba(227, 176, 92, .4); border-radius: 50%;
}
.role-top h3 { font-size: 1.6rem; }
.role-top .slots { color: var(--muted); font-size: .88rem; }
.role-desc { color: #cfc8ba; margin: 0; white-space: pre-wrap; }
.chip-label { font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: 4px; font-size: .9rem; font-weight: 500;
  background: rgba(147, 173, 140, .14); color: #c4d7bf;
}
.chip.cand { background: transparent; border: 1px dashed var(--line-strong); color: var(--text); }
.chip.me { box-shadow: inset 0 0 0 1px var(--candle); }
.chip button { border: 0; background: none; cursor: pointer; padding: 0 2px; color: inherit; font-size: 1rem; line-height: 1; opacity: .7; }
.chip button:hover { opacity: 1; }
.role-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; align-items: center; }
.role-actions select { flex: 1; min-width: 150px; padding: 7px 10px; }
.full-tag { color: var(--sage); font-weight: 500; font-size: .9rem; }

/* ---------- gestione ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 26px; margin-bottom: 24px; }
.panel h2 { margin-bottom: 4px; }
.panel .hint, .hint { color: var(--muted); margin: 0 0 18px; }
.phase-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; counter-reset: ph; }
.phase-opt {
  counter-increment: ph;
  border: 1px solid var(--line-strong); background: transparent; border-radius: var(--r); padding: 16px; cursor: pointer; text-align: left;
}
.phase-opt b { display: block; font-family: var(--serif); font-weight: 400; font-size: 1.5rem; }
.phase-opt b::before { content: counter(ph) '. '; color: var(--muted); }
.phase-opt span { font-size: .88rem; color: var(--muted); }
.phase-opt:hover { border-color: var(--text); }
.phase-opt.on { border-color: var(--candle); background: rgba(227, 176, 92, .08); }
.phase-opt.on b::before { color: var(--candle); }
@media (max-width: 640px) { .phase-switch { grid-template-columns: 1fr; } }

.row-form { display: grid; grid-template-columns: 2fr 1fr auto; gap: 12px; align-items: end; }
.row-form label.field { margin: 0; }
@media (max-width: 760px) { .row-form { grid-template-columns: 1fr; } }
.table-wrap { overflow-x: auto; margin-top: 20px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .85rem; font-weight: 500; color: var(--muted); }
td .actions { display: flex; gap: 6px; justify-content: flex-end; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 4px; font-size: .8rem; font-weight: 500; }
.tag.yes { background: rgba(147, 173, 140, .16); color: #c4d7bf; }
.tag.no { color: var(--muted); border: 1px solid var(--line-strong); }
.tag.admin { color: var(--candle); border: 1px solid rgba(227, 176, 92, .4); }
details.bulk { margin-top: 18px; }
details.bulk summary { cursor: pointer; color: var(--candle); font-weight: 500; }
.stat-row { display: flex; gap: 40px; flex-wrap: wrap; margin: 8px 0 12px; }
.stat b { display: block; font-family: var(--serif); font-weight: 400; font-size: 2.8rem; line-height: 1; }
.stat span { font-size: .9rem; color: var(--muted); }

/* ---------- avvisi ---------- */
.notice { border-left: 2px solid var(--candle); padding: 4px 0 4px 18px; margin-bottom: 28px; text-align: left; }
.notice b { font-weight: 600; }
.notice p { margin: 4px 0 0; color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 70;
  background: var(--text); color: #1d1a14; font-weight: 600;
  padding: 11px 20px; border-radius: var(--r); box-shadow: 0 12px 30px rgba(0, 0, 0, .4);
  animation: rise-in .2s ease-out; max-width: calc(100% - 32px); text-align: center;
}
.toast.err { background: var(--brick); color: #fff; }
.loading { padding: 60px 0; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- form a più campi ---------- */
#user-form { grid-template-columns: 1fr 1fr auto; }
.pw-form { grid-template-columns: 1fr 1fr 1fr auto; }
@media (max-width: 760px) { #user-form, .pw-form { grid-template-columns: 1fr; } }

/* ---------- contatore messaggi nuovi ---------- */
.nav a .badge {
  min-width: 20px; height: 20px; padding: 0 6px; margin-left: 7px; align-self: center;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px; background: var(--candle); color: var(--bg);
  font-size: .75rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1;
}

/* ---------- chat ---------- */
.chat {
  display: flex; flex-direction: column;
  height: min(calc(100dvh - 330px), 760px); min-height: 380px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  overflow: hidden;
}
.chat-list {
  flex: 1; overflow-y: auto; padding: 22px 22px 8px;
  display: flex; flex-direction: column; gap: 14px;
  overscroll-behavior: contain;
}
.chat-list > .loading { padding: 20px 0; }
.chat-empty { margin: auto; color: var(--muted); }
.msg { max-width: min(78%, 560px); align-self: flex-start; }
.msg.mine { align-self: flex-end; }
.msg-head {
  display: flex; align-items: center; gap: 8px;
  font-size: .82rem; color: var(--muted); margin: 0 4px 4px;
}
.msg.mine .msg-head { justify-content: flex-end; }
.msg-head b { color: var(--text); font-weight: 600; }
.msg-head time { font-variant-numeric: tabular-nums; }
.msg-body {
  padding: 9px 14px; border-radius: 12px 12px 12px 3px;
  background: var(--raised); border: 1px solid var(--line);
  white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45;
}
.msg.mine .msg-body {
  border-radius: 12px 12px 3px 12px;
  background: rgba(227, 176, 92, .2); border-color: rgba(227, 176, 92, .36);
}
.msg-del {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  font-size: 1.05rem; line-height: 1; padding: 0 2px; opacity: 0; transition: opacity .15s;
}
.msg:hover .msg-del, .msg-del:focus-visible { opacity: 1; }
@media (hover: none) { .msg-del { opacity: .6; } }
.msg-del:hover { color: var(--brick); }
.chat-form {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 14px; border-top: 1px solid var(--line); background: var(--bg);
}
.chat-form .input { flex: 1; resize: none; min-height: 44px; max-height: 160px; line-height: 1.4; }
@media (max-width: 560px) {
  .chat { height: calc(100dvh - 230px); min-height: 320px; }
  .chat-list { padding: 16px 12px 6px; }
  .msg { max-width: 88%; }
}

/* ---------- foto in chat ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.chat-photo-btn {
  flex: none; width: 44px; height: 44px; display: grid; place-items: center;
  border: 1px solid var(--line-strong); border-radius: var(--r); color: var(--muted); cursor: pointer;
  transition: color .15s, border-color .15s;
}
.chat-photo-btn:hover, .chat-photo-btn:focus-within { color: var(--candle); border-color: var(--candle); }
.chat-preview {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px; border-top: 1px solid var(--line); background: var(--bg);
}
.chat-preview img { width: 64px; height: 64px; object-fit: cover; border-radius: var(--r); border: 1px solid var(--line-strong); }
.msg-photo {
  display: block; width: fit-content; max-width: 100%; padding: 0; line-height: 0;
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
  background: var(--raised); cursor: zoom-in; margin-bottom: 4px;
}
.msg.mine .msg-photo { margin-left: auto; border-color: rgba(227, 176, 92, .36); }
.msg-photo img { display: block; max-width: min(320px, 70vw); max-height: 300px; width: auto; height: auto; }
.msg:has(.msg-photo) .msg-body { width: fit-content; max-width: 100%; }
.msg.mine:has(.msg-photo) .msg-body { margin-left: auto; }
.chat-photo-full { margin: 0 auto; max-height: calc(100vh - 120px); width: auto; border-radius: var(--r); }
