/* ─────────────────────────────────────────────────────────────────
   Componenti riusabili. Tutto stateless: classi modifier per le varianti.
   ───────────────────────────────────────────────────────────────── */

/* ── Button ────────────────────────────────────────────────────── */
.btn {
  --bg: var(--c-surface);
  --fg: var(--c-text);
  --bd: var(--c-border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--tap-rec);
  padding: 0 var(--sp-5);
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--bd);
  border-radius: var(--r-md);
  font-weight: var(--fw-medium);
  font-size: var(--fs-body);
  line-height: 1;
  user-select: none;
  transition: transform var(--t-fast) var(--easing),
              background-color var(--t-base) var(--easing),
              border-color var(--t-base) var(--easing);
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn[disabled], .btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn--primary {
  --bg: var(--c-brand);
  --fg: var(--c-text-on-brand);
  --bd: var(--c-brand);
}
.btn--primary:hover { --bg: var(--c-brand-hover); --bd: var(--c-brand-hover); }
.btn--primary:active { --bg: var(--c-brand-active); }

.btn--soft {
  --bg: var(--c-brand-soft);
  --fg: var(--c-brand-text);
  --bd: var(--c-brand-soft-2);
}

.btn--ghost {
  --bg: transparent;
  --bd: transparent;
}
.btn--ghost:hover { --bg: var(--c-surface-sunk); }

.btn--danger {
  --bg: var(--c-surface);
  --fg: var(--c-danger);
  --bd: var(--c-danger);
}
.btn--danger:hover { --bg: var(--c-danger-soft); }

.btn--lg { min-height: var(--tap-lg); padding: 0 var(--sp-6); font-size: 17px; }
.btn--sm { min-height: 36px; padding: 0 var(--sp-3); font-size: var(--fs-body-sm); }
.btn--icon { width: var(--tap-rec); padding: 0; }
.btn--block { width: 100%; }

/* ── Input ─────────────────────────────────────────────────────── */
.input,
.select,
.textarea {
  display: block;
  width: 100%;
  min-height: var(--tap-rec);
  padding: 0 var(--sp-4);
  background: var(--c-surface);
  color: var(--c-text);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-md);
  font-size: 17px;            /* ≥17px → iOS non zoomma sul focus */
  line-height: 1.3;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color var(--t-base) var(--easing),
              box-shadow var(--t-base) var(--easing);
}
.textarea { min-height: 96px; padding: var(--sp-3) var(--sp-4); resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--c-brand);
  box-shadow: 0 0 0 3px rgba(212,83,126,0.18);
}
.input::placeholder { color: var(--c-text-subtle); }

.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.field-label {
  font-size: var(--fs-body-sm);
  font-weight: var(--fw-medium);
  color: var(--c-text-muted);
}

/* ── Card ──────────────────────────────────────────────────────── */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
}
.card--flush { padding: 0; }
.card--soft  { background: var(--c-surface-alt); }
.card--brand {
  background: var(--c-brand-soft);
  border-color: var(--c-brand-soft-2);
}

/* ── Badge / Chip ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  font-size: var(--fs-label);
  font-weight: var(--fw-bold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: var(--r-pill);
  background: var(--c-surface-sunk);
  color: var(--c-text-muted);
  white-space: nowrap;
}
.badge--brand   { background: var(--c-brand-soft);   color: var(--c-brand-text); }
.badge--success { background: var(--c-success-soft); color: var(--c-success); }
.badge--warning { background: var(--c-warning-soft); color: var(--c-warning); }
.badge--danger  { background: var(--c-danger-soft);  color: var(--c-danger); }
.badge--info    { background: var(--c-info-soft);    color: var(--c-info); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 32px;
  padding: 0 var(--sp-3);
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-pill);
  font-size: var(--fs-body-sm);
  color: var(--c-text);
  cursor: pointer;
  user-select: none;
}
.chip[aria-pressed="true"], .chip.is-active {
  background: var(--c-brand);
  color: var(--c-text-on-brand);
  border-color: var(--c-brand);
}

/* Sub-view dei tab: visibile solo quando .is-active. !important per battere
   l'utility .col (display:flex) che spesso viene applicata insieme a .view. */
[data-view].view:not(.is-active) { display: none !important; }

/* ── Tab bar ───────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--c-surface-sunk);
  border-radius: var(--r-md);
  padding: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto;
  min-height: 40px;
  padding: 0 var(--sp-4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  font-size: var(--fs-body-sm);
  font-weight: var(--fw-medium);
  color: var(--c-text-muted);
  background: transparent;
  border: none;
  border-radius: var(--r-sm);
  white-space: nowrap;
  cursor: pointer;
}
.tab[aria-selected="true"] {
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: var(--sh-sm);
}

/* ── Topbar ────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: var(--topbar-h);
  padding: 0 var(--sp-4);
  padding-top: var(--safe-top);
  background: var(--c-bg);
  border-bottom: 1px solid var(--c-border);
}
.topbar__title {
  flex: 1;
  font-size: var(--fs-h2);
  font-weight: var(--fw-bold);
  text-align: center;
}
.topbar__icon-btn {
  width: var(--tap-rec);
  height: var(--tap-rec);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border-radius: var(--r-md);
  color: var(--c-text);
}
.topbar__icon-btn:hover { background: var(--c-surface-sunk); }

/* ── Bottom action bar (sticky) ────────────────────────────────── */
.bottom-bar {
  position: sticky;
  bottom: 0;
  z-index: var(--z-topbar);
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + var(--safe-bottom));
  background: var(--c-bg);
  border-top: 1px solid var(--c-border);
}

/* ── Bottom sheet ──────────────────────────────────────────────── */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20,20,40,0.45);
  z-index: var(--z-overlay);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base) var(--easing);
}
.sheet-overlay.is-open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: var(--z-sheet);
  background: var(--c-surface);
  border-top-left-radius: var(--r-xl);
  border-top-right-radius: var(--r-xl);
  padding: var(--sp-5) var(--sp-4) calc(var(--sp-5) + var(--safe-bottom));
  max-height: 85dvh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform var(--t-slow) var(--easing);
  box-shadow: var(--sh-lg);
}
.sheet.is-open { transform: translateY(0); }
.sheet__handle {
  width: 40px;
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--c-border-strong);
  margin: 0 auto var(--sp-4);
}
.sheet__title {
  font-size: var(--fs-h2);
  font-weight: var(--fw-bold);
  margin-bottom: var(--sp-4);
  text-align: center;
}

/* ── Toast ─────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--sp-7) + var(--safe-bottom));
  transform: translate(-50%, 24px);
  z-index: var(--z-toast);
  padding: var(--sp-3) var(--sp-5);
  background: #1a1a22;
  color: #fff;
  border-radius: var(--r-md);
  font-size: var(--fs-body-sm);
  box-shadow: var(--sh-lg);
  opacity: 0;
  transition: opacity var(--t-base), transform var(--t-base);
  pointer-events: none;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }
.toast--success { background: var(--c-success); }
.toast--danger { background: var(--c-danger); }

/* ── Score panel (broadcast) ───────────────────────────────────── */
.score-panel {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
}
.score-panel__side { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); min-width: 0; }
.score-panel__team {
  font-size: var(--fs-label);
  font-weight: var(--fw-bold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--c-text-muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.score-panel__num {
  font-size: var(--fs-display);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.score-panel__num--us { color: var(--c-brand); }
.score-panel__center {
  text-align: center;
  font-size: var(--fs-body-sm);
  color: var(--c-text-muted);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.score-panel__sets { font-variant-numeric: tabular-nums; }

.score-step {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
}
.score-step__col { display: flex; gap: var(--sp-2); }
.score-step__btn {
  flex: 1;
  min-height: var(--tap-lg);
  border-radius: var(--r-md);
  border: 1px solid var(--c-border-strong);
  background: var(--c-surface);
  font-size: 22px;
  font-weight: var(--fw-bold);
  color: var(--c-text);
}
.score-step__btn.is-plus { border-color: var(--c-brand); color: var(--c-brand); }
.score-step__btn.is-minus { color: var(--c-text-muted); }
.score-step__btn:active { transform: scale(0.97); }

/* ── Player grid (campo) ───────────────────────────────────────── */
.player-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
}
.player-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 88px;
  padding: var(--sp-3);
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-md);
  text-align: center;
  cursor: pointer;
  transition: transform var(--t-fast) var(--easing), border-color var(--t-base);
  position: relative;
}
.player-card:active { transform: scale(0.97); }
.player-card.is-selected {
  border-color: var(--c-brand);
  border-width: 2px;
  background: var(--c-brand-soft);
}
.player-card.is-libero {
  background: var(--c-info-soft);
  border-color: var(--c-info);
}
.player-card__num {
  font-size: 26px;
  font-weight: var(--fw-bold);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.player-card__name {
  margin-top: var(--sp-1);
  font-size: 11px;
  font-weight: var(--fw-medium);
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-card__role {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 10px;
  font-weight: var(--fw-bold);
  color: var(--c-text-subtle);
}

/* ── Action grid (sheet azioni / qualità) ─────────────────────── */
.action-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
}
.action-grid--qualities { grid-template-columns: repeat(5, 1fr); }
.action-tile {
  min-height: var(--tap-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: var(--sp-3) var(--sp-2);
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-md);
  font-size: var(--fs-body-sm);
  font-weight: var(--fw-medium);
  color: var(--c-text);
  cursor: pointer;
}
.action-tile:active { transform: scale(0.97); }
.action-tile__icon { font-size: 20px; line-height: 1; }
.action-tile.is-positive { border-color: var(--c-success); color: var(--c-success); }
.action-tile.is-negative { border-color: var(--c-danger); color: var(--c-danger); }
.action-tile.is-neutral  { border-color: var(--c-warning); color: var(--c-warning); }

/* ── Event feed ───────────────────────────────────────────────── */
.event-feed {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.event-row {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  font-size: var(--fs-body-sm);
}
.event-row__dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--c-text-subtle);
  margin-left: 6px;
}
.event-row__dot.is-positive { background: var(--c-success); }
.event-row__dot.is-negative { background: var(--c-danger); }
.event-row__dot.is-neutral  { background: var(--c-warning); }
.event-row__main { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-row__time { font-size: var(--fs-label); color: var(--c-text-muted); font-variant-numeric: tabular-nums; }
.event-row__del {
  width: 36px; height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  color: var(--c-text-muted);
}
.event-row__del:hover { background: var(--c-surface-sunk); color: var(--c-danger); }

/* ── Liste / table-like ───────────────────────────────────────── */
.list {
  display: flex;
  flex-direction: column;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.list__item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--tap-lg);
  padding: var(--sp-3) var(--sp-4);
  cursor: pointer;
}
.list__item + .list__item { border-top: 1px solid var(--c-divider); }
.list__item:hover { background: var(--c-surface-sunk); }
.list__main { flex: 1; min-width: 0; }
.list__title { font-weight: var(--fw-medium); }
.list__sub { font-size: var(--fs-body-sm); color: var(--c-text-muted); }

/* ── Stat cell (riepilogo) ─────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: var(--sp-3);
}
.stat-cell {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-cell__label {
  font-size: var(--fs-label);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: var(--fw-bold);
  color: var(--c-text-muted);
}
.stat-cell__value {
  font-size: 28px;
  font-weight: var(--fw-bold);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* ── Color swatch (selettore colore squadra) ──────────────────── */
.swatches { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.swatch {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform var(--t-fast);
}
.swatch:active { transform: scale(0.92); }
.swatch.is-selected {
  border-color: var(--c-text);
  outline: 2px solid var(--c-bg);
  outline-offset: -4px;
}

/* ── Empty state ──────────────────────────────────────────────── */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--sp-9) var(--sp-5);
  color: var(--c-text-muted);
  gap: var(--sp-3);
}
.empty__title { font-size: var(--fs-h2); color: var(--c-text); font-weight: var(--fw-bold); }
.empty__desc  { max-width: 38ch; }
