/* ESN ASSI Secret Santa - tema natalizio con i colori ESN. Nessun font o risorsa esterna (CSP: solo 'self'). */
:root {
  --navy: #0B1F3A;
  --navy-2: #14305a;
  --cyan: #00AEEF;
  --magenta: #EC008C;
  --orange: #F47B20;
  --orange-d: #C25508;
  --green: #7AC143;
  --green-d: #2f7a12;
  --blue: #2E3192;
  --gold: #F5C84C;
  --bg: #EAF3FA;
  --ink: #22314a;
  --muted: #55667f;
  --line: #d3e3f1;
  --card: #ffffff;
  --danger: #b3261e;
  --radius: 16px;
  --shadow: 0 2px 4px rgba(11, 31, 58, .06), 0 8px 24px rgba(11, 31, 58, .08);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg) linear-gradient(180deg, #dcecf8 0, var(--bg) 320px) no-repeat;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
body.modal-open { overflow: hidden; }
.wrap { width: 100%; max-width: 980px; margin: 0 auto; padding: 0 16px; }
main { flex: 1; padding-top: 20px; padding-bottom: 40px; outline: none; }
.skip { position: absolute; left: -999px; top: 0; background: #fff; padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }
.sr-only { 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; }
.err-text { color: var(--danger); }
code { background: #eef4fa; padding: 1px 6px; border-radius: 6px; font-size: .9em; }

h1, h2, h3 { line-height: 1.2; color: var(--blue); margin: 0 0 .5em; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; margin-top: 1.2em; }
p { margin: 0 0 .8em; }
a { color: var(--blue); }
:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; border-radius: 6px; }

/* ---------- intestazione ---------- */
.site-header { position: relative; background: var(--navy); color: #fff; overflow: hidden; }
.stripe { height: 6px; background: linear-gradient(90deg, var(--cyan), var(--magenta), var(--orange), var(--green)); }
.header-in { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 14px; padding-bottom: 14px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; }
.brand-emoji { font-size: 2rem; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text small { color: var(--cyan); font-weight: 700; letter-spacing: .14em; text-transform: uppercase; font-size: .72rem; }
.brand-text strong { font-size: 1.35rem; }
.userbar { display: flex; align-items: center; gap: 10px; }
.who { display: flex; align-items: center; gap: 8px; font-weight: 600; min-width: 0; }
.who-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }

.snow { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.snow span { position: absolute; top: -20px; left: var(--x); font-size: var(--s); color: rgba(255, 255, 255, .75); animation: fall var(--d) linear var(--w) infinite; }
@keyframes fall { to { transform: translateY(140px) rotate(180deg); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .snow { display: none; } * { scroll-behavior: auto !important; } }

.site-footer { background: var(--navy); color: #8FA3BF; font-size: .85rem; padding: 16px 0; text-align: center; }

/* ---------- card e notifiche ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; margin-bottom: 18px; border: 1px solid #e3eef7; }
.lead { font-size: 1.05rem; color: var(--muted); }
.lead.small { font-size: .95rem; }
.notice { border-radius: 12px; padding: 12px 14px; margin: 0 0 14px; border: 1px solid transparent; }
.notice.info { background: #e8f6fd; border-color: #b9e3f7; color: #0b4a66; }
.notice.ok { background: #eef8e4; border-color: #cfe9b3; color: #26510f; }
.notice.warn { background: #fff5e0; border-color: #f6dca4; color: #6b4300; }
.notice.err { background: #fdebea; border-color: #f4c3bf; color: #7a1610; }
.notice:empty { display: none; }
.notice .btn { margin-left: 6px; }
.hint { color: var(--muted); font-size: .875rem; margin: 6px 0 0; }

/* ---------- badge ---------- */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; background: #e7edf4; color: var(--ink); white-space: nowrap; }
.badge.ok { background: #e3f4d1; color: #26510f; }
.badge.warn { background: #ffecc2; color: #6b4300; }
.badge.err { background: #fbdcd9; color: #7a1610; }
.badge.gold { background: var(--gold); color: #3d2d00; }
.badge.muted { background: #e7edf4; color: var(--muted); }

/* ---------- bottoni ---------- */
.btn { appearance: none; border: 2px solid transparent; border-radius: 999px; padding: 10px 20px; font: inherit; font-weight: 700; cursor: pointer; line-height: 1.2; transition: transform .08s, box-shadow .15s, background .15s; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--orange-d); color: #fff; box-shadow: 0 3px 0 #8f3d04; }
.btn.primary:hover:not(:disabled) { background: #d4600a; }
.btn.secondary { background: #fff; color: var(--blue); border-color: var(--cyan); }
.btn.secondary:hover:not(:disabled) { background: #e8f6fd; }
.btn.ghost { background: transparent; color: var(--blue); border-color: var(--line); }
.btn.ghost:hover:not(:disabled) { background: #f1f7fc; }
.btn.ghost.on-dark { color: #fff; border-color: rgba(255, 255, 255, .45); }
.btn.ghost.on-dark:hover:not(:disabled) { background: rgba(255, 255, 255, .12); }
.btn.danger { background: var(--danger); color: #fff; box-shadow: 0 3px 0 #7f1a14; }
.btn.danger-text { color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn.busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.busy::after { content: ""; position: absolute; width: 18px; height: 18px; border: 3px solid rgba(255, 255, 255, .55); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.btn.secondary.busy::after, .btn.ghost.busy::after { border-color: rgba(46, 49, 146, .3); border-top-color: var(--blue); }
@keyframes spin { to { transform: rotate(360deg); } }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; align-items: center; }

/* ---------- form ---------- */
.field { margin: 0 0 16px; }
label { display: block; font-weight: 600; margin-bottom: 6px; }
input[type="text"], input[type="email"], input[type="password"], input[type="url"], input[type="number"], input[type="datetime-local"], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; min-height: 44px;
}
textarea { resize: vertical; }
textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--cyan); outline: none; box-shadow: 0 0 0 3px rgba(0, 174, 239, .25); }
input:disabled, select:disabled, textarea:disabled { background: #f3f7fb; color: var(--muted); cursor: not-allowed; }
.input-row { display: flex; gap: 8px; align-items: stretch; }
.input-row .btn { flex: none; }
label.check { display: flex; align-items: flex-start; gap: 10px; font-weight: 500; margin: 10px 0; cursor: pointer; }
label.check input { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: var(--blue); }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } }

/* scelte a pillola (radio accessibili) */
.choices { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0 16px; }
.choice { position: relative; margin: 0; font-weight: 700; cursor: pointer; }
.choice input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.choice span { display: inline-block; padding: 10px 20px; border-radius: 999px; border: 2px solid var(--line); background: #fff; color: var(--ink); min-height: 44px; line-height: 1.4; }
.choice input:checked + span { background: var(--blue); border-color: var(--blue); color: #fff; }
.choice input:focus-visible + span { outline: 3px solid var(--cyan); outline-offset: 2px; }
.choice input:disabled { cursor: not-allowed; }
.choice input:disabled + span { opacity: .55; }
.choice input:disabled:checked + span { opacity: .8; }
.choices.is-disabled .choice { cursor: not-allowed; }

/* ---------- login ---------- */
.login-card { max-width: 480px; margin: 24px auto; text-align: center; }
.login-card .lead { margin-bottom: 20px; }
.login-emoji { font-size: 3rem; line-height: 1; margin-bottom: 8px; }
.login-form { text-align: left; }
.login-form .notice { text-align: left; }

/* ---------- banner evento ---------- */
.banner { background: linear-gradient(135deg, #ffffff 0, #f1f9fe 100%); border-top: 6px solid var(--magenta); }
.banner-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.banner-top h2 { margin: 0; font-size: 1.5rem; }
.banner-desc { margin-top: 10px; color: var(--muted); }
.facts { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 14px; }
@media (min-width: 700px) { .facts { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); } }
.fact { display: flex; gap: 10px; align-items: flex-start; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.fact-icon { font-size: 1.4rem; line-height: 1.2; }
.fact-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.fact-value { font-weight: 600; overflow-wrap: anywhere; }
.venue-link { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; }

/* ---------- RSVP a passi ---------- */
.step { border: 2px dashed var(--line); border-radius: 14px; padding: 16px; margin: 14px 0; }
.step-head { display: flex; align-items: center; gap: 10px; }
.step-head h3 { margin: 0; }
.step-n { width: 30px; height: 30px; border-radius: 50%; background: var(--orange-d); color: #fff; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.saved-line { margin: 12px 0 0; color: var(--green-d); font-weight: 600; font-size: .9rem; }

/* ---------- wishlist ---------- */
.gifts { display: grid; gap: 12px; margin: 10px 0; }
.gift { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; background: #f7fbfe; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.gift-n { width: 28px; height: 28px; border-radius: 50%; background: var(--green-d); color: #fff; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; }
.gift-fields { display: grid; gap: 8px; }
.gift .btn { grid-column: 2; justify-self: start; }

/* ---------- destinatario ---------- */
.reveal { border-top: 6px solid var(--green); }
.recipient { display: flex; align-items: center; gap: 14px; background: linear-gradient(135deg, #fff5e0, #fde6f3); border: 2px solid var(--gold); border-radius: 16px; padding: 18px; margin: 8px 0; }
.recipient-emoji { font-size: 2.6rem; }
.recipient-name { font-size: 1.7rem; font-weight: 800; color: var(--blue); overflow-wrap: anywhere; }
.block { margin-top: 14px; }
.block h3 { margin-top: 0; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.wish-list { padding-left: 20px; margin: 0; }
.wish-list li { margin-bottom: 10px; overflow-wrap: anywhere; }

/* ---------- schede ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 16px; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.tab { appearance: none; flex: none; border: 2px solid var(--line); background: #fff; color: var(--blue); font: inherit; font-weight: 700; padding: 9px 18px; border-radius: 999px; cursor: pointer; white-space: nowrap; min-height: 44px; }
.tab[aria-selected="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
.main-tabs .tab[aria-selected="true"] { background: var(--magenta); border-color: var(--magenta); }
@media (max-width: 640px) { .tabs { flex-wrap: wrap; overflow-x: visible; } }

/* ---------- tabelle ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; background: #fff; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { background: #f1f7fc; color: var(--blue); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.cell-main { font-weight: 600; overflow-wrap: anywhere; }
.actions-cell { white-space: nowrap; }
.actions-cell .btn { margin: 2px 4px 2px 0; }
@media (max-width: 720px) {
  .table.stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table.stack, .table.stack tbody, .table.stack tr, .table.stack td { display: block; width: 100%; }
  .table.stack tr { border-bottom: 3px solid var(--line); padding: 6px 0; }
  .table.stack td { border: 0; padding: 6px 12px; }
  .table.stack td[data-label]::before { content: attr(data-label); display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
  .actions-cell { white-space: normal; }
}

/* ---------- contatori ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: #f7fbfe; border: 1px solid var(--line); border-left: 6px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.tile.ok { border-left-color: var(--green); }
.tile.err { border-left-color: var(--danger); }
.tile.warn { border-left-color: var(--orange); }
.tile.blue { border-left-color: var(--cyan); }
.tile-n { font-size: 1.8rem; font-weight: 800; color: var(--navy); line-height: 1.1; }
.tile-l { font-size: .82rem; color: var(--muted); font-weight: 600; }

/* ---------- regole sorteggio ---------- */
.rule-form { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 760px) { .rule-form { grid-template-columns: 1fr 1fr auto; align-items: center; } }
.rules { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; }
.rules li { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #f7fbfe; border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; flex-wrap: wrap; }

/* ---------- messaggi post-sorteggio ---------- */
.msgs { display: grid; gap: 12px; margin-top: 16px; }
.msg { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.msg header { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; background: #f1f7fc; }
.msg header strong { flex: 1 1 200px; overflow-wrap: anywhere; }
.msg pre { margin: 0; padding: 12px; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: .9rem; }

/* ---------- anteprima email ---------- */
.preview { width: 100%; height: 520px; border: 2px solid var(--line); border-radius: 12px; background: #fff; }
.report { margin-top: 20px; }

/* ---------- modale e toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(11, 31, 58, .6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 18px; padding: 24px; width: 100%; max-width: 480px; max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.modal h3 { margin-top: 0; font-size: 1.25rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.toasts { position: fixed; left: 12px; right: 12px; bottom: 12px; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 60; pointer-events: none; }
.toast { pointer-events: auto; max-width: 520px; width: 100%; background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); border-left: 6px solid var(--cyan); animation: pop .2s ease-out; }
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--magenta); }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } }

@media (max-width: 480px) {
  .card { padding: 16px; }
  h1 { font-size: 1.5rem; }
  .recipient-name { font-size: 1.35rem; }
  .brand-text strong { font-size: 1.15rem; }
  .who-name { max-width: 30vw; }
}
