/* Pannello staff di AFTER.
   Layout: una barra traslucida in alto, la lista delle feste come tabella che sul telefono
   diventa una pila di schede, e la festa aperta in un pannello laterale sopra la lista.
   Colori: gli stessi dell'app (AFTER/Theme/AppColor.swift), solo tema scuro come l'app. */
:root {
  --background: #161826;
  --surface: #1e2030;
  --surface-2: #262938;
  --surface-3: #2f3243;
  --line: rgba(178, 182, 202, .14);
  --line-strong: rgba(178, 182, 202, .26);
  --text: #ecebf1;
  --text-2: #b2b6ca;
  --text-3: #8a8ea1;
  --accent: #9184d9;
  --accent-soft: rgba(145, 132, 217, .16);
  --on-accent: #15141f;
  --warning: #e3b35b;
  --warning-soft: rgba(227, 179, 91, .14);
  --success: #7cc9a0;
  --danger: #ef6b6b;
  --danger-soft: rgba(239, 107, 107, .12);
  --scrim: rgba(8, 9, 16, .62);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --radius: 10px;
  --radius-large: 16px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.defs { position: absolute; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font: 0.9375rem/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.625rem; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.1875rem; line-height: 1.25; font-weight: 650; letter-spacing: -0.012em; text-wrap: balance; }
h3 { font-size: 0.8125rem; font-weight: 600; color: var(--text-2); letter-spacing: 0.01em; }

input, select, textarea, button { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* MARK: Controlli */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, transform .1s ease-out;
}
.button:hover:not(:disabled) { background: var(--surface-3); }
.button:active:not(:disabled) { transform: scale(.97); }
.button:disabled { opacity: .4; cursor: default; }
.button.primary { background: var(--accent); border-color: transparent; color: var(--on-accent); font-weight: 650; }
.button.primary:hover:not(:disabled) { background: #a092e4; }
.button.quiet { background: transparent; border-color: transparent; color: var(--text-2); }
.button.quiet:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.button.danger { background: transparent; border-color: rgba(239, 107, 107, .45); color: var(--danger); }
.button.danger:hover:not(:disabled) { background: var(--danger-soft); }
.button.danger-solid { background: var(--danger); border-color: transparent; color: #1c0f12; font-weight: 650; }
.button.is-busy { color: transparent; position: relative; pointer-events: none; }
.button.is-busy::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid var(--on-accent);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.button.quiet.is-busy::after, .button:not(.primary).is-busy::after { border-color: var(--text-2); border-right-color: transparent; }

.icon-button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: var(--surface-2);
  border: 0;
  border-radius: 50%;
  color: var(--text-2);
  cursor: pointer;
}
.icon-button:hover { background: var(--surface-3); color: var(--text); }
.icon-button:active { transform: scale(.94); }
.icon-button svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.field { display: grid; gap: 6px; min-width: 0; }
.field > span { font-size: 0.8125rem; font-weight: 550; color: var(--text-2); }
.field small { font-size: 0.75rem; color: var(--text-3); }
.field.narrow { max-width: 220px; }

input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 11px;
  background: var(--background);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--text-3); }
:is(input, select, textarea):hover { border-color: rgba(178, 182, 202, .4); }
:is(input, select, textarea):focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="datetime-local"] { font-variant-numeric: tabular-nums; }
input[type="checkbox"] { accent-color: var(--accent); }

.select {
  appearance: none;
  padding-right: 32px !important;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 17px) 52%, calc(100% - 12px) 52%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

.form-error {
  padding: 9px 12px;
  background: var(--danger-soft);
  border-radius: var(--radius);
  color: #f6a0a0;
  font-size: 0.875rem;
}

/* Due o tre scelte che si escludono: un controllo segmentato, come su iOS. */
.segmented {
  display: inline-flex;
  gap: 2px;
  margin: 0;
  padding: 3px;
  background: var(--surface-2);
  border: 0;
  border-radius: 11px;
}
.segment {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 12px;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 0.8125rem;
  font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .15s, color .15s;
}
.segment:hover { color: var(--text); }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment.active, .segment:has(input:checked) { background: var(--surface-3); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .3); }
.segment:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.pill.private { background: var(--accent-soft); color: #b9b0ee; }
.pill.featured { background: rgba(236, 235, 241, .1); color: var(--text); }
.pill.pending { background: var(--warning-soft); color: var(--warning); }
.pill.accepted { background: rgba(124, 201, 160, .14); color: var(--success); }
.pill.declined { background: var(--surface-3); color: var(--text-3); }
.pill.ended { background: transparent; border: 1px solid var(--line-strong); color: var(--text-3); }

/* MARK: Marchio */

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); }
.logo { width: 54px; height: 20px; }
.brand-tag {
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: #b9b0ee;
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.04em;
}
.brand-large .logo { width: 84px; height: 31px; }

/* MARK: Accesso */

.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px));
  background: radial-gradient(120% 70% at 50% 0%, rgba(145, 132, 217, .12), transparent 60%), var(--background);
}
.login-card {
  display: grid;
  gap: 16px;
  width: min(380px, 100%);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
}
.login-intro { color: var(--text-2); font-size: 0.875rem; margin-bottom: 4px; }
.login-card .button.primary { min-height: 42px; margin-top: 4px; font-size: 0.9375rem; }

/* MARK: Struttura */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px 24px;
  min-height: 60px;
  padding: 10px max(20px, env(safe-area-inset-right, 0px)) 10px max(20px, env(safe-area-inset-left, 0px));
  background: rgba(22, 24, 38, .72);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  box-shadow: 0 1px 0 var(--line);
}
.account { display: flex; align-items: center; gap: 10px; margin-left: auto; min-width: 0; }
.account-email { overflow: hidden; color: var(--text-2); font-size: 0.8125rem; text-overflow: ellipsis; white-space: nowrap; }
.role { color: var(--text-3); font-size: 0.75rem; white-space: nowrap; }

.view {
  display: grid;
  gap: 16px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px max(20px, env(safe-area-inset-right, 0px)) 48px max(20px, env(safe-area-inset-left, 0px));
}
.view-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; }
.summary { margin-top: 4px; color: var(--text-2); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.summary strong { color: var(--warning); font-weight: 600; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.search { position: relative; flex: 1 1 320px; min-width: 0; }
.search svg {
  position: absolute;
  top: 50%;
  left: 11px;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  fill: none;
  stroke: var(--text-3);
  stroke-width: 1.8;
  stroke-linecap: round;
  pointer-events: none;
}
.search input[type="search"] { padding-left: 34px; padding-right: 34px; }
.search input::-webkit-search-cancel-button { display: none; }
.search kbd {
  position: absolute;
  top: 50%;
  right: 9px;
  transform: translateY(-50%);
  padding: 1px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: var(--text-3);
  font: 0.6875rem var(--font);
  pointer-events: none;
}
.search:focus-within kbd { display: none; }
.toolbar .select { width: auto; min-width: 190px; }

/* MARK: Lista delle feste */

.list {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-large);
}
.list-head, .row {
  display: grid;
  grid-template-columns: minmax(200px, 2.2fr) minmax(130px, 1.1fr) minmax(150px, 1.6fr) minmax(150px, 1.5fr) minmax(110px, .9fr) 20px;
  gap: 16px;
  align-items: start;
  padding: 12px 18px;
}
.list-head {
  padding-block: 10px;
  border-bottom: 1px solid var(--line);
  color: var(--text-3);
  font-size: 0.75rem;
  font-weight: 550;
}
.list-head::after { content: ""; }
.rows { margin: 0; padding: 0; list-style: none; }
.rows li + li .row { box-shadow: inset 0 1px 0 var(--line); }
.row {
  width: 100%;
  background: transparent;
  border: 0;
  border-radius: 0;
  text-align: left;
  cursor: pointer;
  transition: background-color .12s;
}
.row:hover { background: var(--surface-2); }
.row:active { background: var(--surface-3); }
.row:focus-visible { outline-offset: -2px; border-radius: 4px; }
.cell { display: grid; gap: 3px; min-width: 0; font-size: 0.875rem; }
.cell .main { overflow-wrap: anywhere; }
.cell .sub { color: var(--text-3); font-size: 0.8125rem; overflow-wrap: anywhere; }
.cell .label { display: none; }
.title-cell .main { font-weight: 650; font-size: 0.9375rem; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.when-cell .main, .guests-cell .main { font-variant-numeric: tabular-nums; }
.when-cell .soon { color: var(--accent); }
.guests-cell .pill { justify-self: start; }
.chevron { align-self: center; width: 8px; height: 8px; border-top: 2px solid var(--text-3); border-right: 2px solid var(--text-3); transform: rotate(45deg); opacity: .7; }

/* Al posto della lista mentre carica: righe della stessa forma. */
.skeleton .bar { height: 10px; border-radius: 5px; background: var(--surface-3); animation: pulse 1.4s ease-in-out infinite; }
.skeleton .bar.wide { width: 70%; height: 12px; }
.skeleton .bar.mid { width: 55%; }
.skeleton .bar.short { width: 35%; }
.skeleton .row { cursor: default; }
.skeleton .row:hover { background: transparent; }

.list-state { display: grid; justify-items: center; gap: 6px; padding: 48px 20px; text-align: center; }
.list-state-title { font-weight: 650; }
.list-state-text { max-width: 44ch; color: var(--text-2); font-size: 0.875rem; }
.list-state .button { margin-top: 8px; }

.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.range { color: var(--text-3); font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.pager-buttons { display: flex; gap: 8px; }

/* MARK: Registro */

.audit { display: grid; gap: 24px; max-width: 860px; }
.day { display: grid; gap: 8px; }
.day h3 { color: var(--text-3); }
.entries { margin: 0; padding: 0; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-large); }
.entries li { display: grid; gap: 6px; padding: 14px 18px; }
.entries li + li { box-shadow: inset 0 1px 0 var(--line); }
.entry-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.entry-title { font-weight: 650; }
.entry-meta { color: var(--text-3); font-size: 0.8125rem; }
.diff { display: grid; grid-template-columns: max-content 1fr; gap: 3px 12px; margin: 0; font-size: 0.8125rem; }
.diff dt { color: var(--text-3); }
.diff dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.diff del { color: var(--text-3); text-decoration-color: rgba(138, 142, 161, .6); }
.diff ins { color: var(--text); text-decoration: none; }
.reason { color: var(--text-2); font-size: 0.875rem; }
.empty-note { color: var(--text-3); font-size: 0.875rem; }

/* MARK: Pannello della festa */

dialog { padding: 0; color: var(--text); border: 0; }
dialog::backdrop { background: var(--scrim); }

.sheet {
  width: min(620px, 100vw);
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 0 0 auto;
  background: var(--surface);
  box-shadow: -1px 0 0 var(--line), -30px 0 80px rgba(0, 0, 0, .4);
}
.sheet[open] { animation: sheet-in .32s var(--ease); }
.sheet[open]::backdrop { animation: fade-in .25s ease-out; }
.sheet { overflow: hidden; }
/* minmax(0, 1fr): senza, la parte centrale cresce col contenuto e scorre tutto il pannello. */
.sheet form { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; }
.sheet-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--line);
}
.sheet-title { display: grid; gap: 4px; min-width: 0; }
.sheet-title h2 { overflow-wrap: anywhere; }
.sheet-sub { color: var(--text-3); font-size: 0.8125rem; }
/* Flex e non grid: in un grid che scorre, le righe con overflow nascosto si schiacciano a zero. */
.sheet-body { display: flex; flex-direction: column; gap: 26px; min-height: 0; overflow-y: auto; padding: 18px 22px 28px; overscroll-behavior: contain; }
.sheet-body > * { flex-shrink: 0; }
.sheet-foot { display: grid; gap: 10px; padding: 12px 22px max(14px, env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); background: var(--surface); }
.sheet-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.dirty-note { margin-right: auto; color: var(--warning); font-size: 0.8125rem; }
.discard { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.discard span { margin-right: auto; color: var(--text-2); font-size: 0.875rem; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; overflow: hidden; background: var(--line); border-radius: 12px; }
.stat { display: grid; gap: 2px; padding: 12px 14px; background: var(--surface-2); }
.stat b { font-size: 1.25rem; font-weight: 650; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.stat span { color: var(--text-3); font-size: 0.75rem; }
.stat.attention b { color: var(--warning); }

.group { display: grid; gap: 12px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; border: 0; }
.chips legend { margin-bottom: 8px; padding: 0; font-size: 0.8125rem; font-weight: 550; color: var(--text-2); }
.chip {
  position: relative; /* tiene dentro la chip la casella nascosta, che altrimenti allunga il pannello */
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--text-2);
  font-size: 0.8125rem;
  font-weight: 550;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:checked) { background: var(--accent-soft); border-color: rgba(145, 132, 217, .55); color: #c8c0f3; }
.chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip:active { transform: scale(.97); }

.toggle {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: 12px;
  cursor: pointer;
}
.toggle span { display: grid; gap: 2px; order: -1; }
.toggle strong { font-size: 0.9375rem; font-weight: 600; }
.toggle small { color: var(--text-3); font-size: 0.8125rem; }
.toggle input {
  appearance: none;
  position: relative;
  width: 44px;
  height: 26px;
  margin: 0;
  border-radius: 13px;
  background: var(--surface-3);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  cursor: pointer;
  transition: background-color .2s;
}
.toggle input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
  transition: transform .25s var(--ease);
}
.toggle input:checked { background: var(--accent); box-shadow: none; }
.toggle input:checked::after { transform: translateX(18px); }

.people, .changes { display: grid; margin: 0; padding: 0; list-style: none; }
.people li { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 12px; padding: 9px 0; }
.people li + li, .changes li + li { box-shadow: inset 0 1px 0 var(--line); }
.people .name { font-size: 0.9375rem; }
.people .email { grid-column: 1; color: var(--text-3); font-size: 0.8125rem; overflow-wrap: anywhere; }
.people .pill { grid-column: 2; grid-row: 1 / span 2; }
.changes li { display: grid; gap: 6px; padding: 10px 0; }

.danger-zone { padding: 16px; border: 1px solid rgba(239, 107, 107, .25); border-radius: 12px; }
.danger-zone p { color: var(--text-2); font-size: 0.875rem; }
.danger-zone .button { justify-self: start; }

/* Conferma della cancellazione: piccola, al centro, come un avviso di sistema. */
.alert {
  width: min(440px, calc(100vw - 32px));
  padding: 22px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
}
.alert[open] { animation: pop-in .22s var(--ease); }
.alert form { display: grid; gap: 14px; }
.alert p { color: var(--text-2); font-size: 0.875rem; }
.alert-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* MARK: Avvisi */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom, 0px));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(47, 50, 67, .92);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .35);
  font-size: 0.875rem;
  font-weight: 550;
  transform: translateX(-50%);
  animation: toast-in .3s var(--ease);
}
.toast.error { border-color: rgba(239, 107, 107, .5); color: #f6a0a0; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .45; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-in { from { transform: translateX(40px); opacity: 0; } }
@keyframes pop-in { from { transform: scale(.96); opacity: 0; } }
@keyframes toast-in { from { transform: translate(-50%, 12px); opacity: 0; } }

/* MARK: Telefono */

@media (max-width: 860px) {
  .list-head { display: none; }
  .row {
    grid-template-columns: 1fr 1fr;
    gap: 10px 14px;
    padding: 14px 16px;
  }
  .title-cell { grid-column: 1 / -1; }
  .cell .label { display: block; color: var(--text-3); font-size: 0.6875rem; font-weight: 550; }
  .chevron { display: none; }
  .account-email { display: none; }
}

@media (max-width: 600px) {
  .topbar { gap: 10px; padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px)); }
  .brand-tag { display: none; }
  .view { padding: 20px max(16px, env(safe-area-inset-right, 0px)) 40px max(16px, env(safe-area-inset-left, 0px)); }
  .toolbar .segmented, .toolbar .select { flex: 1 1 100%; }
  .toolbar .segment { flex: 1; justify-content: center; }
  .pair, .stats { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .sheet-head, .sheet-body, .sheet-foot { padding-inline: 16px; }
  .field.narrow { max-width: none; }
  .role { display: none; }
  .search kbd { display: none; }
  .stat { padding: 10px 12px; }
  .stat b { font-size: 1.0625rem; }
  .search input[type="search"] { padding-right: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .sheet[open] { animation: fade-in .2s ease-out !important; }
}

@media (prefers-reduced-transparency: reduce) {
  .topbar { background: var(--background); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .toast { background: var(--surface-3); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
