/* ============================================================
   La Mia Squadra — Fantacalcio Auction Assistant
   Dark Mode Premium · spaziatura ariosa
   ============================================================ */

:root {
  --bg:            #0F111A;
  --bg-2:          #12141f;
  --surface:       #1A1D29;
  --surface-2:     #20242f;
  --surface-3:     #272c3a;
  --line:          rgba(255, 255, 255, 0.08);
  --line-strong:   rgba(255, 255, 255, 0.16);

  --text:          #F5F6FA;
  --text-dim:      #9aa1b4;
  --text-faint:    #69708a;

  --gold:          #FBBF24;
  --gold-soft:     #f6d27a;
  --purple:        #8B5CF6;
  --blue:          #3B82F6;
  --green:         #22C55E;
  --yellow:        #F5C518;
  --red:           #EF4444;

  /* Colori reparto */
  --role-p:        #22C55E;
  --role-d:        #3B82F6;
  --role-c:        #F59E0B;
  --role-a:        #EF4444;

  --radius:        18px;
  --radius-sm:     12px;
  --radius-pill:   999px;
  --shadow:        0 12px 32px rgba(0, 0, 0, 0.45);
  --shadow-soft:   0 6px 18px rgba(0, 0, 0, 0.35);
  --ring:          0 0 0 3px rgba(139, 92, 246, 0.45);
  --space:         clamp(16px, 2vw, 24px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 12% -10%, rgba(139, 92, 246, 0.16), transparent 60%),
    radial-gradient(1000px 600px at 100% 0%, rgba(59, 130, 246, 0.12), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ----------------------------- Header ----------------------------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-direction: column; gap: 16px;
  padding: 18px clamp(16px, 3vw, 32px);
  background: linear-gradient(180deg, rgba(18, 20, 31, 0.94), rgba(15, 17, 26, 0.85));
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.header-top, .header-bottom {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space); flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand__logo { width: 56px; height: 56px; object-fit: contain; filter: drop-shadow(0 4px 10px rgba(0,0,0,.5)); }
.brand__title { margin: 0; font-size: clamp(1.1rem, 1.6vw, 1.5rem); font-weight: 900; letter-spacing: 1px; }
.brand__subtitle { margin: 3px 0 0; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 2px; color: var(--gold-soft); }

/* Budget globale */
.budget { display: flex; gap: 12px; flex-wrap: wrap; }
.stat {
  display: flex; flex-direction: column; gap: 3px;
  padding: 12px 20px; min-width: 120px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow-soft);
}
.stat__label { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 1.4px; color: var(--text-dim); }
.stat__value { font-size: 1.7rem; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; }
.stat__unit { font-size: 0.66rem; color: var(--text-faint); letter-spacing: 1px; }
.stat--remaining { border-color: rgba(251, 191, 36, 0.35); }
.stat--remaining .stat__value { color: var(--gold); }
.stat--remaining.is-negative { border-color: rgba(239, 68, 68, 0.5); }
.stat--remaining.is-negative .stat__value { color: var(--red); }

/* Ripartizione budget per reparto (in alto, modificabile) */
.alloc { display: flex; gap: 10px; flex-wrap: wrap; align-items: stretch; }
.alloc__item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.alloc__role {
  width: 26px; height: 26px; display: grid; place-items: center;
  border-radius: 8px; font-weight: 900; font-size: 0.8rem; color: #07100a;
}
.alloc--P .alloc__role { background: var(--role-p); }
.alloc--D .alloc__role { background: var(--role-d); color: #061226; }
.alloc--C .alloc__role { background: var(--role-c); color: #271a02; }
.alloc--A .alloc__role { background: var(--role-a); color: #2a0606; }
.alloc__pct {
  width: 56px; font: inherit; font-weight: 800; font-variant-numeric: tabular-nums;
  text-align: right; color: var(--text);
  padding: 6px 8px; background: var(--surface-3); border: 1px solid var(--line-strong); border-radius: 8px;
}
.alloc__pct:focus { outline: none; box-shadow: var(--ring); }
.alloc__sign { color: var(--text-dim); font-weight: 700; margin-left: -4px; }
.alloc__target { font-size: 0.78rem; color: var(--text-faint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.alloc__total {
  display: inline-flex; align-items: center; padding: 8px 12px;
  font-size: 0.78rem; font-weight: 800; color: var(--text-dim);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.alloc__total.is-off { color: var(--red); border-color: rgba(239,68,68,.5); }

/* Azioni */
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  appearance: none; display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 18px; font-size: 0.92rem; font-weight: 700; color: var(--text);
  background: linear-gradient(180deg, var(--surface-3), var(--surface-2));
  border: 1px solid var(--line-strong); border-radius: var(--radius-pill); box-shadow: var(--shadow-soft);
  cursor: pointer; transition: transform .1s ease, filter .15s ease;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn--primary { color: #fff; background: linear-gradient(180deg, #a78bfa, var(--purple)); border-color: rgba(0,0,0,.2); }
.btn__icon { font-size: 1.05rem; line-height: 1; }

/* ----------------------------- Board ----------------------------- */
.board {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: var(--space); padding: var(--space) clamp(16px, 3vw, 32px);
  max-width: 1700px; margin: 0 auto;
}

.section {
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.section__head { display: flex; align-items: center; gap: 12px; padding: 16px 20px 14px; }
.section--P .section__head { border-top: 3px solid var(--role-p); }
.section--D .section__head { border-top: 3px solid var(--role-d); }
.section--C .section__head { border-top: 3px solid var(--role-c); }
.section--A .section__head { border-top: 3px solid var(--role-a); }
.section__badge { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; font-weight: 900; box-shadow: var(--shadow-soft); }
.section--P .section__badge { background: var(--role-p); color: #07100a; }
.section--D .section__badge { background: var(--role-d); color: #061226; }
.section--C .section__badge { background: var(--role-c); color: #271a02; }
.section--A .section__badge { background: var(--role-a); color: #2a0606; }
.section__headtext { flex: 1; min-width: 0; }
.section__title { margin: 0; font-size: 1.05rem; font-weight: 800; }
.section__sub { margin-top: 3px; font-size: 0.8rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.section__sub .count { font-weight: 800; color: var(--text); }
.section__sub .money { color: var(--gold-soft); font-weight: 700; }
.section__sub .money.is-over { color: var(--red); }
.section__sort {
  font: inherit; font-size: 0.78rem; font-weight: 600; color: var(--text-dim);
  padding: 7px 10px; background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: 10px; cursor: pointer; max-width: 130px;
}
.section__sort:focus { outline: none; box-shadow: var(--ring); }

/* Barra avanzamento spesa reparto */
.section__progress { height: 5px; background: var(--surface-3); margin: 0 20px 8px; border-radius: var(--radius-pill); overflow: hidden; }
.section__progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--green), var(--gold)); transition: width .25s ease; }
.section__progress.is-over > i { background: var(--red); }

.section__list { display: flex; flex-direction: column; }

/* Riga giocatore (impilata: nome+costo, poi badge+stato) */
.player { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; transition: background .12s ease; }
.player:hover { background: rgba(255,255,255,0.02); }
.player__top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.player__name { font-weight: 700; font-size: 1.02rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player__cost { font-weight: 800; font-variant-numeric: tabular-nums; font-size: 1.15rem; color: var(--gold); white-space: nowrap; }
.player__cost::after { content: " cr"; font-size: 0.7rem; color: var(--text-faint); font-weight: 600; }
.player__meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.badge {
  display: inline-block; flex: 0 0 auto;
  font-size: 0.64rem; font-weight: 800; letter-spacing: 0.5px;
  padding: 5px 11px; border-radius: var(--radius-pill); text-transform: uppercase; white-space: nowrap;
}
.badge--TOP      { background: var(--purple); color: #fff; }
.badge--SEMITOP  { background: var(--blue);   color: #fff; }
.badge--TITOLARE { background: var(--green);  color: #06210f; }
.badge--SCOMMESSA{ background: var(--yellow); color: #2a2300; }
.badge--none { color: var(--text-faint); font-size: 0.8rem; font-weight: 600; }

.status-select {
  font: inherit; font-size: 0.84rem; font-weight: 600; color: var(--text);
  padding: 8px 12px; background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: 10px; cursor: pointer;
}
.status-select:focus { outline: none; box-shadow: var(--ring); }

.player__actions { display: flex; gap: 6px; margin-left: auto; }
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px;
  background: var(--surface-3); border: 1px solid var(--line); color: var(--text-dim);
  cursor: pointer; font-size: 1rem; transition: filter .15s ease, color .15s ease, transform .1s ease;
}
.icon-btn:hover { filter: brightness(1.2); color: var(--text); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.icon-btn--danger:hover { color: var(--red); }

.section__empty { padding: 22px 20px; text-align: center; color: var(--text-faint); font-size: 0.9rem; border-top: 1px solid var(--line); }

.section__add {
  width: 100%; padding: 14px 20px; text-align: left;
  background: transparent; border: none; border-top: 1px solid var(--line);
  color: var(--gold-soft); font: inherit; font-weight: 700; font-size: 0.9rem; cursor: pointer;
  transition: background .12s ease;
}
.section__add:hover { background: rgba(251, 191, 36, 0.08); }
.section__add:focus-visible { outline: none; box-shadow: var(--ring); }

/* ----------------------------- Pannello budget ----------------------------- */
.budget-panel { max-width: 1700px; margin: 0 auto; padding: 0 clamp(16px, 3vw, 32px) calc(var(--space) * 2); }
.budget-panel__form {
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px 24px;
}
.budget-panel__title { margin: 0; font-size: 1.1rem; font-weight: 800; }
.budget-panel__hint { margin: 6px 0 16px; color: var(--text-dim); font-size: 0.86rem; }
.budget-panel__fields { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }
.budget-panel__fields .field { flex: 1; min-width: 200px; }
.budget-panel__fields .btn { white-space: nowrap; }

/* ----------------------------- Campi / Modale ----------------------------- */
.field { display: flex; flex-direction: column; gap: 8px; }
.field__label { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); }
.field__input {
  font: inherit; color: var(--text); padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
}
.field__input:focus { outline: none; box-shadow: var(--ring); border-color: var(--purple); }
select.field__input { appearance: none; }

.modal { border: none; padding: 0; background: transparent; color: var(--text); max-width: 460px; width: calc(100% - 32px); }
.modal::backdrop { background: rgba(7, 9, 15, 0.7); backdrop-filter: blur(4px); }
.modal__form {
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 24px; display: flex; flex-direction: column; gap: 18px;
}
.modal__title { margin: 0; font-size: 1.25rem; font-weight: 800; }
.modal__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

.role-picker, .badge-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.pick {
  flex: 1; min-width: 64px; padding: 11px 10px; text-align: center; font-weight: 700; font-size: 0.85rem;
  border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line-strong);
  color: var(--text-dim); cursor: pointer; transition: all .12s ease;
}
.pick:focus-visible { outline: none; box-shadow: var(--ring); }
.pick.is-active { color: var(--text); border-color: var(--purple); background: rgba(139, 92, 246, 0.18); }
.pick--none.is-active { border-color: var(--line-strong); background: var(--surface-3); }

/* ----------------------------- Toast ----------------------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(24px);
  background: var(--surface-3); border: 1px solid var(--line-strong); color: var(--text);
  padding: 12px 20px; border-radius: var(--radius-pill); box-shadow: var(--shadow);
  font-weight: 600; font-size: 0.9rem; opacity: 0; pointer-events: none;
  transition: opacity .25s ease, transform .25s ease; z-index: 50;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.is-error { border-color: var(--red); color: #ffd9d9; }

/* ----------------------------- Responsive ----------------------------- */
@media (max-width: 900px) { .board { grid-template-columns: 1fr; } }
@media (max-width: 600px) {
  .header-top, .header-bottom { flex-direction: column; align-items: stretch; }
  .budget { width: 100%; }
  .stat { flex: 1; min-width: 0; }
  .alloc { width: 100%; }
  .alloc__item { flex: 1 1 calc(50% - 5px); }
  .actions { width: 100%; }
  .actions .btn { flex: 1; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
