/* ============================================================
   MusicLeague — Design System
   Riscritto da zero. Mobile-first.
   ============================================================ */

/* ============================================================
   1. DESIGN TOKENS
   ============================================================ */
:root {
  /* — COLORI — */
  --bg:           #0a0a10;
  --bg-elevated:  #12121a;
  --surface:      #16161f;
  --surface-2:    #1c1c28;
  --surface-3:    #232333;

  --text:         #f5f5f7;
  --text-2:       #a8a8b8;
  --text-3:       #6b6b7a;

  --border:       rgba(255, 255, 255, 0.06);
  --border-2:     rgba(255, 255, 255, 0.10);
  --border-3:     rgba(255, 255, 255, 0.16);

  --accent:        #7d7aff;
  --accent-light:  #a8a5ff;
  --accent-dark:   #5a57d4;
  --accent-bg:     rgba(125, 122, 255, 0.10);
  --accent-bg-2:   rgba(125, 122, 255, 0.16);

  --gold:        #e8c96e;
  --gold-bg:     rgba(232, 201, 110, 0.12);

  /* Colori podio classifiche (più vivaci e distinguibili) */
  --podio-gold:   #f5c842;
  --podio-silver: #d8d8e0;
  --podio-bronze: #cd7f32;

  --success:     #30d158;
  --success-bg:  rgba(48, 209, 88, 0.12);
  --warning:     #ff9f0a;
  --warning-bg:  rgba(255, 159, 10, 0.12);
  --danger:      #ff453a;
  --danger-bg:   rgba(255, 69, 58, 0.12);

  /* — SPACING (scala 4) — */
  --s-1:  4px;
  --s-2:  8px;
  --s-3:  12px;
  --s-4:  16px;
  --s-5:  20px;
  --s-6:  24px;
  --s-8:  32px;
  --s-10: 40px;
  --s-12: 48px;
  --s-16: 64px;
  --s-20: 80px;

  /* — RADIUS — */
  --r-sm:   8px;
  --r-md:   12px;
  --r-lg:   16px;
  --r-xl:   24px;
  --r-full: 999px;

  /* — TIPOGRAFIA — */
  --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  /* — OMBRE — */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.45);

  /* — Z-INDEX — */
  --z-header:    100;
  --z-tabbar:    100;
  --z-backdrop:  900;
  --z-drawer:    1000;
  --z-modal:     1100;
  --z-toast:     1200;

  /* — TRANSIZIONI — */
  --t-fast:   120ms ease;
  --t-base:   200ms ease;
  --t-slow:   320ms cubic-bezier(0.2, 0.8, 0.2, 1);

  /* — DIMENSIONI LAYOUT — */
  --header-h:    56px;
  --tabbar-h:    60px;
  --drawer-w:    min(86vw, 320px);
  --container-w: 600px;
  --container-w-wide: 960px;
}

@media (min-width: 768px) {
  :root {
    --header-h: 64px;
  }
}

/* ============================================================
   2. RESET MINIMO
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

img, svg { display: block; max-width: 100%; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  padding: 0;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a { color: var(--accent-light); text-decoration: none; transition: color var(--t-fast); }
a:hover { color: var(--accent); }

::selection { background: var(--accent-bg-2); color: var(--text); }

/* Scrollbar discreta */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-3); border-radius: var(--r-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* Focus visibile (accessibilità) */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ============================================================
   3. TIPOGRAFIA
   ============================================================ */
h1, h2, h3, h4 { margin: 0; line-height: 1.2; font-weight: 600; letter-spacing: -0.01em; }

h1 { font-size: 32px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
h4 { font-size: 16px; }

.display {
  font-size: clamp(40px, 8vw, 64px);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.kicker {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
}

.lead {
  font-size: 18px;
  color: var(--text-2);
  line-height: 1.55;
}

.muted    { color: var(--text-2); }
.muted-2  { color: var(--text-3); }
.text-sm  { font-size: 13px; }
.text-xs  { font-size: 12px; }
.text-caption { font-size: 12px; color: var(--text-3); }

p { margin: 0 0 var(--s-4); }
p:last-child { margin-bottom: 0; }

strong, b { font-weight: 600; }

/* ============================================================
   4. APP SHELL — Layout principale
   ============================================================ */
.app-shell {
  min-height: 100vh;
  padding-top: var(--header-h);
  /* tab-bar height + safe area + margine ampio: lascia respirare l'ultimo contenuto
     così tutti i bottoni in fondo sono sempre cliccabili sopra la tab bar */
  padding-bottom: calc(var(--tabbar-h) + var(--s-20) + env(safe-area-inset-bottom, 0px));
}

.app-main {
  max-width: var(--container-w);
  margin: 0 auto;
  padding: var(--s-5) var(--s-4);
  /* Spazio extra in fondo per evitare che la tab bar copra l'ultimo contenuto.
     Si somma al padding-bottom del .app-shell, dando margine extra di sicurezza. */
  padding-bottom: var(--s-16);
}

.app-main--wide {
  max-width: var(--container-w-wide);
}

/* Shell pubblica (login, verify, reset password) — no header, no tab bar */
.full-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-6) var(--s-4);
}

.full-shell__inner {
  width: 100%;
  max-width: 440px;
}

/* Skip link (accessibility) */
.skip-link {
  position: absolute;
  top: -100px;
  left: var(--s-4);
  padding: var(--s-2) var(--s-4);
  background: var(--accent);
  color: var(--text);
  border-radius: var(--r-sm);
  font-weight: 500;
  z-index: 9999;
  transition: top var(--t-fast);
}
.skip-link:focus { top: var(--s-4); }

/* ============================================================
   5. HEADER FISSO
   ============================================================ */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: rgba(10, 10, 16, 0.85);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  padding: 0 var(--s-3);
  gap: var(--s-3);
}

.app-header__menu-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: background var(--t-fast);
}
.app-header__menu-btn:hover,
.app-header__menu-btn:active { background: var(--surface-2); }
.app-header__menu-btn { position: relative; }
.app-header__menu-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--surface);
  box-sizing: content-box;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex: 1;
  min-width: 0;
}
.app-header__brand-logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}
.app-header__brand-text {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-shrink: 0;
}

.app-header__gems {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 6px var(--s-3);
  background: var(--gold-bg);
  border: 1px solid rgba(232, 201, 110, 0.25);
  border-radius: var(--r-full);
  color: var(--gold);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: filter var(--t-fast);
}
.app-header__gems:hover { filter: brightness(1.15); color: var(--gold); }
.app-header__gems svg { width: 14px; height: 14px; }

/* ============================================================
   PWA — banner installazione
   ============================================================ */
.pwa-banner {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-bar-h, 64px) + 12px);
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 420px;
  z-index: 4000;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: pwaBannerIn 0.3s ease both;
}
@keyframes pwaBannerIn {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.pwa-banner__txt {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.pwa-banner__txt strong { font-size: 14px; font-weight: 600; color: var(--text); }
.pwa-banner__txt span   { font-size: 12px; color: var(--text-3); line-height: 1.35; }
.pwa-banner__txt b      { color: var(--text-2); font-weight: 600; }
.pwa-banner__btn {
  flex-shrink: 0;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  font-size: 13px; font-weight: 600;
  border-radius: var(--r-sm);
  border: none; cursor: pointer;
  transition: background var(--t-fast);
}
.pwa-banner__btn:hover { background: var(--accent-dark, var(--accent)); }
.pwa-banner__close {
  flex-shrink: 0;
  width: 28px; height: 28px;
  font-size: 20px; line-height: 1;
  color: var(--text-3);
  background: transparent; border: none; cursor: pointer;
  border-radius: var(--r-sm);
}
.pwa-banner__close:hover { color: var(--text); background: var(--surface); }

/* ============================================================
   CORNICI AVATAR — riusabili su tutte le pagine
   Da applicare via box-shadow (non occupano spazio nel layout).
   Uso: <img class="av-cornice av-cornice--gold" src="...">
   ============================================================ */
.av-cornice              { border-radius: 50%; }
.av-cornice--standard    { /* nessun effetto, default */ }
/* Alias inglese + italiano (DB salva codici italiani, shop_articoli.colore è in inglese) */
.av-cornice--bronze, .av-cornice--bronzo    { box-shadow: 0 0 0 2.5px #cd7f32, 0 0 6px rgba(205,127,50,.45); }
.av-cornice--silver, .av-cornice--argento   { box-shadow: 0 0 0 2.5px #c0c0c0, 0 0 6px rgba(192,192,192,.45); }
.av-cornice--gold, .av-cornice--oro         { box-shadow: 0 0 0 2.5px #ffd700, 0 0 10px rgba(255,215,0,.55); }
.av-cornice--ruby, .av-cornice--rubino      { box-shadow: 0 0 0 2.5px #e0115f, 0 0 12px rgba(224,17,95,.6); }
.av-cornice--nera, .av-cornice--black       { box-shadow: 0 0 0 2.5px #1a1a1a, 0 0 0 3.5px #555; }
/* Versione large per profilo (border più spesso) */
.av-cornice--lg.av-cornice--bronze, .av-cornice--lg.av-cornice--bronzo    { box-shadow: 0 0 0 4px #cd7f32, 0 0 12px rgba(205,127,50,.5); }
.av-cornice--lg.av-cornice--silver, .av-cornice--lg.av-cornice--argento   { box-shadow: 0 0 0 4px #c0c0c0, 0 0 12px rgba(192,192,192,.5); }
.av-cornice--lg.av-cornice--gold, .av-cornice--lg.av-cornice--oro         { box-shadow: 0 0 0 4px #ffd700, 0 0 18px rgba(255,215,0,.6); }
.av-cornice--lg.av-cornice--ruby, .av-cornice--lg.av-cornice--rubino      { box-shadow: 0 0 0 4px #e0115f, 0 0 20px rgba(224,17,95,.65); }
.av-cornice--lg.av-cornice--nera, .av-cornice--lg.av-cornice--black       { box-shadow: 0 0 0 4px #1a1a1a, 0 0 0 5.5px #555; }

.app-header__avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--r-full);
  border: 1.5px solid var(--border-2);
  overflow: hidden;
  flex-shrink: 0;
  transition: border-color var(--t-fast);
}
.app-header__avatar:hover { border-color: var(--accent); }
.app-header__avatar img { width: 100%; height: 100%; object-fit: cover; }
/* Quando ha una cornice, il box-shadow sostituisce il border default */
.app-header__avatar.av-cornice { border: none; }

/* Campanella notifiche */
.app-header__bell {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: var(--r-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  background: transparent;
  transition: background var(--t-fast), color var(--t-fast);
  flex-shrink: 0;
}
.app-header__bell:hover { background: var(--surface-2); color: var(--text); }
.app-header__bell.has-unread { color: var(--text); }
.app-header__bell-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--surface);
  box-sizing: content-box;
}

/* ============================================================
   6. SIDEBAR DRAWER
   ============================================================ */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: var(--z-backdrop);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}
.sidebar-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--drawer-w);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  z-index: var(--z-drawer);
  transform: translateX(-100%);
  transition: transform var(--t-slow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar.is-open { transform: translateX(0); }

.sidebar__header {
  padding: var(--s-5) var(--s-5) var(--s-4);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--s-3);
}
.sidebar__brand-logo { width: 32px; height: 32px; }
.sidebar__brand-text {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.sidebar__close-btn {
  margin-left: auto;
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  transition: background var(--t-fast);
}
.sidebar__close-btn:hover { background: var(--surface-2); color: var(--text); }

.sidebar__profile {
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--s-3);
}
.sidebar__profile-avatar {
  width: 44px;
  height: 44px;
  border-radius: var(--r-full);
  border: 1.5px solid var(--border-2);
  overflow: hidden;
  flex-shrink: 0;
}
.sidebar__profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.sidebar__profile-info {
  min-width: 0;
  flex: 1;
}
.sidebar__profile-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar__profile-email {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__lega-switcher {
  margin: var(--s-3) var(--s-4);
  position: relative;
}
.sidebar__lega-select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  padding: 10px var(--s-3) 10px var(--s-3);
  padding-right: var(--s-8);
  background: var(--surface);
  border: 1px solid var(--border-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--r-md);
  outline: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'><path d='M1 1l4 4 4-4' stroke='%23a8a8b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right var(--s-3) center;
}
.sidebar__lega-select:focus { border-color: var(--accent); }

.sidebar__nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--s-2) 0 var(--s-4);
}

.sidebar__section {
  padding: var(--s-3) var(--s-5) 0;
}
.sidebar__section-title {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  margin-bottom: var(--s-2);
  padding: 0 var(--s-2);
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 10px var(--s-3);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--r-md);
  text-decoration: none;
  transition: all var(--t-fast);
  border-left: 3px solid transparent;
  margin-left: -3px;
}
.sidebar__link:hover {
  background: var(--surface);
  color: var(--text);
}
.sidebar__link.is-active {
  color: var(--accent-light);
  background: var(--accent-bg);
  border-left-color: var(--accent);
  font-weight: 600;
}
.sidebar__link-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.sidebar__link-badge {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.sidebar__footer {
  padding: var(--s-3) var(--s-5);
  border-top: 1px solid var(--border);
}

/* ============================================================
   7. BOTTOM TAB BAR (mobile primary nav)
   ============================================================ */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(10, 10, 16, 0.92);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
  z-index: var(--z-tabbar);
  display: flex;
  align-items: stretch;
}

.tab-bar__link {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-3);
  text-decoration: none;
  font-size: 10px;
  font-weight: 500;
  transition: color var(--t-fast);
  position: relative;
  padding: var(--s-2) var(--s-1);
}
.tab-bar__link:hover { color: var(--text-2); }
.tab-bar__link.is-active { color: var(--accent); }
.tab-bar__link.is-active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 2px;
  background: var(--accent);
  border-radius: 0 0 var(--r-sm) var(--r-sm);
}
.tab-bar__link-icon {
  width: 22px;
  height: 22px;
}
.tab-bar__link-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* ============================================================
   8. CARD SYSTEM
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-sm);
}
.card--accent {
  border-color: var(--accent-bg-2);
  background: linear-gradient(180deg, var(--accent-bg) 0%, var(--surface) 60%);
}
.card--hoverable {
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}
.card--hoverable:hover {
  background: var(--surface-2);
  border-color: var(--border-2);
}
.card--compact { padding: var(--s-4); }
.card--flat { box-shadow: none; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s-4);
  gap: var(--s-3);
}
.card-header__title {
  font-size: 16px;
  font-weight: 600;
}
.card-body { /* default padding già nella card */ }
.card-footer {
  margin-top: var(--s-4);
  padding-top: var(--s-4);
  border-top: 1px solid var(--border);
}

/* Stack di card con spacing coerente */
.card + .card { margin-top: var(--s-4); }

/* ============================================================
   9. BOTTONI
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: 10px var(--s-4);
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), transform 80ms ease;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}
.btn:active:not([disabled]) { transform: scale(0.98); }
.btn[disabled],
.btn.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
.btn svg { width: 16px; height: 16px; }

.btn--primary {
  background: var(--accent);
  color: #fff;
}
.btn--primary:hover { background: var(--accent-dark); }

.btn--secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-2);
}
.btn--secondary:hover { background: var(--surface-3); border-color: var(--border-3); }

.btn--ghost {
  background: transparent;
  color: var(--text-2);
}
.btn--ghost:hover { background: var(--surface); color: var(--text); }

.btn--danger {
  background: var(--danger);
  color: #fff;
}
.btn--danger:hover { filter: brightness(1.1); }

/* Spotify green (usato per i bottoni "Apri playlist") */
.btn--spotify {
  background: #1DB954;
  color: #000;
  font-weight: 600;
}
.btn--spotify:hover { background: #1ed760; }

/* Gold accent (usato per "Invia canzone" — differenziato dal sondaggio viola) */
.btn--gold {
  background: var(--gold);
  color: var(--bg);
  font-weight: 600;
}
.btn--gold:hover { filter: brightness(1.08); }

.btn--lg {
  padding: 14px var(--s-6);
  font-size: 15px;
  border-radius: var(--r-md);
}
.btn--sm {
  padding: 6px var(--s-3);
  font-size: 13px;
}
.btn--block { width: 100%; }

/* ============================================================
   10. FORM
   ============================================================ */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  margin-bottom: var(--s-4);
}
.field__label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}
.field__hint {
  font-size: 12px;
  color: var(--text-3);
}
.field__error {
  font-size: 12px;
  color: var(--danger);
}

.input, .select, .textarea {
  width: 100%;
  padding: 12px var(--s-4);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: 15px;
  transition: border-color var(--t-fast), background var(--t-fast);
  -webkit-appearance: none;
  appearance: none;
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-2);
}
.input[disabled], .select[disabled], .textarea[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}
.textarea {
  resize: vertical;
  min-height: 80px;
  font-family: inherit;
}
.select {
  cursor: pointer;
  padding-right: var(--s-10);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'><path d='M1 1l4 4 4-4' stroke='%23a8a8b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right var(--s-4) center;
}

.field--error .input,
.field--error .select,
.field--error .textarea {
  border-color: var(--danger);
}

.checkbox {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--s-2);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-2);
}
.checkbox input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border-3);
  border-radius: var(--r-sm);
  background: var(--surface);
  margin: 0;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  transition: all var(--t-fast);
}
.checkbox input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.checkbox input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ============================================================
   11. PILL / BADGE
   ============================================================ */
.pill, .badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 4px 10px;
  border-radius: var(--r-full);
  font-size: 12px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.badge--accent  { background: var(--accent-bg);  color: var(--accent-light); border-color: var(--accent-bg-2); }
.badge--gold    { background: var(--gold-bg);    color: var(--gold);         border-color: rgba(232,201,110,0.25); }
.badge--success { background: var(--success-bg); color: var(--success);      border-color: rgba(48,209,88,0.25); }
.badge--warning { background: var(--warning-bg); color: var(--warning);      border-color: rgba(255,159,10,0.25); }
.badge--danger  { background: var(--danger-bg);  color: var(--danger);       border-color: rgba(255,69,58,0.25); }

.badge--lg {
  padding: 6px var(--s-3);
  font-size: 13px;
}

/* ============================================================
   12. EMPTY STATE
   ============================================================ */
.empty-state {
  padding: var(--s-12) var(--s-4);
  text-align: center;
  color: var(--text-2);
}
.empty-state__icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--s-4);
  color: var(--text-3);
}
.empty-state__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--s-2);
}
.empty-state__desc {
  font-size: 14px;
  color: var(--text-2);
  max-width: 320px;
  margin: 0 auto var(--s-5);
  line-height: 1.5;
}

/* ============================================================
   13. TABELLE
   ============================================================ */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow-x: auto;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th, .table td {
  padding: var(--s-3) var(--s-4);
  text-align: left;
  white-space: nowrap;
}
.table th {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.table td {
  border-bottom: 1px solid var(--border);
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--surface-2); }

.table--striped tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

/* ============================================================
   14. MODALI
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}
.modal-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transform: translateY(100%);
  transition: transform var(--t-slow);
}
.modal-backdrop.is-open .modal { transform: translateY(0); }

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: var(--s-4); }
  .modal {
    border-radius: var(--r-xl);
    transform: translateY(20px) scale(0.96);
    opacity: 0;
    transition: transform var(--t-slow), opacity var(--t-base);
  }
  .modal-backdrop.is-open .modal { transform: translateY(0) scale(1); opacity: 1; }
}

.modal__handle {
  width: 36px;
  height: 4px;
  background: var(--border-3);
  border-radius: var(--r-full);
  margin: var(--s-3) auto 0;
}
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--border);
  gap: var(--s-3);
}
.modal__title {
  font-size: 17px;
  font-weight: 600;
}
.modal__close-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  transition: background var(--t-fast);
}
.modal__close-btn:hover { background: var(--surface-2); color: var(--text); }
.modal__body { padding: var(--s-5); }
.modal__footer {
  display: flex;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

/* ============================================================
   15. UTILITIES MINIME
   ============================================================ */
.flex   { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center  { align-items: center; }
.items-start   { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.flex-1        { flex: 1; }
.flex-wrap     { flex-wrap: wrap; }

.grid   { display: grid; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); }

.gap-1 { gap: var(--s-1); }
.gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); }
.gap-4 { gap: var(--s-4); }
.gap-5 { gap: var(--s-5); }
.gap-6 { gap: var(--s-6); }

.mt-2 { margin-top: var(--s-2); }
.mt-3 { margin-top: var(--s-3); }
.mt-4 { margin-top: var(--s-4); }
.mt-5 { margin-top: var(--s-5); }
.mt-6 { margin-top: var(--s-6); }
.mt-8 { margin-top: var(--s-8); }
.mb-2 { margin-bottom: var(--s-2); }
.mb-3 { margin-bottom: var(--s-3); }
.mb-4 { margin-bottom: var(--s-4); }
.mb-6 { margin-bottom: var(--s-6); }

.text-center { text-align: center; }
.text-right  { text-align: right; }
.hidden { display: none !important; }

.divider {
  height: 1px;
  background: var(--border);
  margin: var(--s-5) 0;
}

/* ============================================================
   16. ANIMAZIONI SOBRIE
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn 320ms cubic-bezier(0.2, 0.8, 0.2, 1) both; }

/* Riduci animazioni se preferenza utente */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   17. MEDIA QUERIES
   ============================================================ */
@media (min-width: 640px) {
  .app-main { padding: var(--s-6) var(--s-5); }
  h1 { font-size: 36px; }
}

@media (min-width: 1024px) {
  .app-main { padding: var(--s-8) var(--s-6); }
  h1 { font-size: 40px; }
  .grid-md-2 { grid-template-columns: 1fr 1fr; }
  .grid-md-3 { grid-template-columns: repeat(3, 1fr); }
}
