@font-face {
  font-family: Inter;
  src: url("/assets/inter.ttf") format("truetype");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --ink: #172033;
  --muted: #5f6773;
  --paper: #f4f7f3;
  --card: #ffffff;
  --line: #e5e9e3;
  --navy: #111827;
  --lime: #c9f31d;
  --danger: #b83220;
  --danger-soft: #fff0ed;
  --ok-soft: #eaf8be;
  --ok-ink: #3e5000;
  --monthly-start: #123b4a;
  --monthly-end: #087f8c;
  --radius: 24px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); font-weight: 800; letter-spacing: -.045em; }
h2 { font-size: 1.15rem; font-weight: 800; letter-spacing: -.03em; }
a { color: var(--monthly-end); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--monthly-end); outline-offset: 2px; }

.eyebrow { color: var(--muted); font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.muted { color: var(--muted); font-size: .86rem; font-weight: 600; }
.stack { display: grid; gap: 16px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.spread { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px;
  border: 1px solid transparent; border-radius: 13px;
  font-weight: 800; text-decoration: none; cursor: pointer;
}
.button:disabled { opacity: .55; cursor: not-allowed; }
.button.primary { background: var(--lime); color: var(--navy); }
.button.dark { background: var(--navy); color: #fff; }
.button.ghost { background: var(--card); border-color: #d5dbd3; color: var(--ink); }
.button.danger { background: var(--danger-soft); color: var(--danger); }
.button.small { min-height: 36px; padding: 6px 11px; font-size: .82rem; }
.icon-button { width: 44px; padding: 0; }

.field { display: grid; gap: 6px; font-size: .84rem; font-weight: 700; min-width: 0; }
.field input, .field select, .field textarea, .input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 13px; background: #fbfcfa;
  font-weight: 500;
}
.field textarea { min-height: 84px; resize: vertical; }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: .8rem; font-weight: 700; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: .9rem; font-weight: 700; }
.check input { flex: 0 0 20px; width: 20px; height: 20px; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.alert { padding: 12px 14px; border-radius: 13px; background: var(--danger-soft); color: var(--danger); font-size: .9rem; font-weight: 700; }
.notice { padding: 12px 14px; border-radius: 13px; background: var(--ok-soft); color: var(--ok-ink); font-size: .9rem; font-weight: 700; }

.card { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.card:not(.stack) > h2 { margin-bottom: 12px; }

/* Accesso */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: clamp(0px, 4vw, 48px); }
.login-shell {
  width: min(1080px, 100%); display: grid; overflow: hidden; background: var(--card);
  grid-template-columns: minmax(320px, .85fr) minmax(0, 1.15fr);
  border-radius: 34px; box-shadow: 0 28px 80px rgba(23, 32, 51, .16);
}
.login-form { display: grid; align-content: center; gap: 16px; padding: clamp(28px, 5vw, 64px); }
.login-form h1 { margin-bottom: 8px; }
.login-visual { min-height: 560px; background: #0eb3a8; }
.login-visual img { width: 100%; height: 100%; display: block; object-fit: cover; }
.brand-fit { color: var(--monthly-end); }

/* Struttura */
.shell { min-height: 100vh; display: grid; grid-template-columns: 230px minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 6px;
  padding: 24px 18px; color: #fff;
  background: linear-gradient(145deg, var(--monthly-start), var(--monthly-end));
}
.brand { display: flex; align-items: center; gap: 12px; margin: 0 6px 26px; color: #fff; font-size: 1.15rem; font-weight: 900; letter-spacing: -.02em; text-decoration: none; }
.brand img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; }
.brand span { color: var(--lime); }
.nav-link {
  display: flex; align-items: center; min-height: 44px; padding: 0 13px; border-radius: 13px;
  color: #fff; font-weight: 700; text-decoration: none;
}
.nav-link:hover { background: rgba(255, 255, 255, .1); }
.nav-link.active { background: rgba(255, 255, 255, .16); color: var(--lime); font-weight: 800; }
.nav-link:focus-visible { outline-color: #fff; }
.sidebar-footer { margin-top: auto; }
.sidebar-footer button { width: 100%; background: transparent; border: 0; cursor: pointer; }
.main { min-width: 0; padding: clamp(18px, 4vw, 44px); padding-bottom: 48px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; }
.mobile-nav { display: none; }

/* Dashboard */
.hero { position: relative; min-height: 300px; display: flex; align-items: flex-end; overflow: hidden; padding: clamp(22px, 4vw, 38px); border-radius: 30px; background: var(--navy); color: #fff; }
.hero > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 75% 30%; }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(17, 24, 39, .92) 0%, rgba(17, 24, 39, .55) 42%, transparent 72%); }
.hero-content { position: relative; z-index: 1; display: grid; justify-items: start; gap: 8px; max-width: 460px; }
.hero .eyebrow { color: var(--lime); }
.hero h2 { font-size: clamp(1.9rem, 5vw, 3rem); letter-spacing: -.045em; line-height: 1.05; }
.xp-orb {
  position: absolute; z-index: 1; top: 18px; left: 18px; width: 84px; height: 84px;
  display: grid; place-content: center; text-align: center;
  border: 2px solid #fff; border-radius: 50%;
  background: var(--monthly-end); color: #fff;
}
.xp-orb strong { font-size: 1.15rem; font-weight: 900; line-height: 1; }
.xp-orb span { font-size: .62rem; font-weight: 800; letter-spacing: .12em; }
.hero-content.with-orb { padding-top: 96px; }
.stats { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-top: 16px; }
.stat-value { margin-top: 8px; font-size: 1.7rem; font-weight: 900; letter-spacing: -.04em; }
.columns { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); margin-top: 16px; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid #eef1ed; color: inherit; text-decoration: none; }
.list-row:last-child { border-bottom: 0; }
.list-row strong { font-weight: 800; }

.badge { display: inline-block; padding: 4px 9px; border-radius: 99px; background: #eef1ed; color: #39424f; font-size: .72rem; font-weight: 800; white-space: nowrap; }
.badge.completed, .badge.modified { background: var(--ok-soft); color: var(--ok-ink); }
.badge.partial { background: #fff2cc; color: #6f4b00; }
.badge.missed { background: var(--danger-soft); color: var(--danger); }
.badge.planned { background: #e3eef6; color: #1e4a6a; }

/* Calendario */
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin-top: 16px; }
.calendar-head { padding: 4px; color: var(--muted); font-size: .75rem; font-weight: 800; text-align: center; }
.day { display: grid; align-content: start; gap: 4px; min-height: 104px; padding: 7px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.day.outside { background: transparent; opacity: .55; }
.day.today { border: 2px solid var(--monthly-end); }
.day-number { display: block; color: inherit; font-size: .8rem; font-weight: 800; text-decoration: none; }
.event { display: block; overflow: hidden; padding: 3px 6px; border-radius: 8px; background: #e3eef6; color: #1e4a6a; font-size: .72rem; font-weight: 700; text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
.event.completed, .event.modified { background: var(--ok-soft); color: var(--ok-ink); }
.event.partial { background: #fff2cc; color: #6f4b00; }
.event.missed { background: var(--danger-soft); color: var(--danger); }
.calendar.week .day { min-height: 200px; }

/* Allenamenti */
.exercise-row { display: grid; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: #fbfcfa; }
.exercise-row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.metrics { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .88rem; }
.metrics b { font-weight: 800; }

/* Catalogo */
.catalog { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); }
.exercise-card { display: grid; overflow: hidden; padding: 0; color: inherit; text-decoration: none; }
.exercise-card:hover { border-color: var(--monthly-end); }
.exercise-thumb { width: 100%; aspect-ratio: 16 / 9; display: grid; place-items: center; background: #e9efe8; object-fit: cover; color: var(--muted); font-size: .8rem; font-weight: 700; }
.exercise-card-body { display: grid; gap: 6px; padding: 14px; }
.media-preview { width: 100%; max-height: 320px; border-radius: 16px; background: #000; object-fit: contain; }
.progress { width: 100%; height: 10px; accent-color: var(--monthly-end); }

/* Premi e XP */
.reward-card.available { border-color: var(--monthly-end); }
.ticket { font-size: .82rem; font-weight: 800; letter-spacing: .06em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ticket.large { margin-top: 12px; padding: 14px; border-radius: 13px; background: var(--ok-soft); color: var(--ok-ink); font-size: 1.15rem; text-align: center; }
.ticket-side { display: grid; justify-items: end; gap: 2px; }
.plain-link { color: inherit; text-decoration: none; gap: 8px; }
.rule-group { margin: 0; padding: 0; border: 0; }
.rule-group legend { margin-bottom: 10px; padding: 0; font-size: .9rem; font-weight: 800; }
.mobile-only { display: none; }

/* Misure */
.measure-row { padding: 12px 0; border-bottom: 1px solid #eef1ed; }
.measure-row:last-child { border-bottom: 0; }
.measure-row summary { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; cursor: pointer; list-style: none; }
.measure-row summary::-webkit-details-marker { display: none; }
.measure-row strong { font-weight: 800; }
.measure-values { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(190px, 100%), 1fr)); gap: 8px 16px; margin: 12px 0; }
.measure-values dt { color: var(--muted); font-size: .78rem; font-weight: 700; }
.measure-values dd { margin: 0; font-weight: 800; }
.measure-row .row { margin-top: 10px; }

/* Challenge */
.exercise-thumb.challenge-thumb { padding: 14px; object-fit: contain; }

.dash-alert { display: block; margin-top: 16px; }
.link-button { padding: 8px 0; border: 0; background: none; color: var(--muted); font: inherit; font-size: .9rem; font-weight: 700; text-decoration: underline; cursor: pointer; }

/* Importazione */
.error-list, .plain-list { display: grid; gap: 6px; margin: 0; padding-left: 18px; font-size: .9rem; font-weight: 600; }
.error-list code { overflow-wrap: anywhere; font-size: .8rem; font-weight: 800; }
.notice p { margin: 0; overflow-wrap: anywhere; }

/* Menu completo del telefono */
.menu-button { width: 100%; border: 0; cursor: pointer; font: inherit; background: transparent; flex-direction: column; gap: 4px; }
.burger { display: block; width: 18px; height: 2px; margin: 4px 0; border-radius: 2px; background: currentColor; box-shadow: 0 -5px 0 currentColor, 0 5px 0 currentColor; }
.menu-sheet { position: fixed; inset: auto 0 0; width: 100%; max-width: none; margin: 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); border-radius: 22px 22px 0 0; color: #fff; background: linear-gradient(145deg, var(--monthly-start), var(--monthly-end)); }
.menu-sheet nav { display: grid; gap: 2px; }
.menu-footer { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255, 255, 255, .25); }
.menu-footer .nav-link { justify-content: center; border: 0; font: inherit; font-weight: 700; background: rgba(255, 255, 255, .12); cursor: pointer; }

/* Allenamento guidato */
.guided { display: grid; gap: 16px; }
.guided-head { gap: 8px; }
.guided-summary { min-height: 44px; display: flex; align-items: center; font-weight: 800; cursor: pointer; }
details.card summary { font-weight: 800; cursor: pointer; }
details.card p { margin-top: 10px; overflow-wrap: anywhere; }
.guided-clock { color: var(--monthly-end); font-size: clamp(4rem, 22vw, 7rem); font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: -.04em; line-height: 1; text-align: center; }
.guided-clock.small { font-size: clamp(3rem, 16vw, 4.5rem); }
.guided-timer { display: grid; justify-items: center; gap: 8px; padding: 14px; border-radius: 18px; background: #f1f5ef; }
.guided-recovery { justify-items: center; text-align: center; }
.guided-center { justify-content: center; }
.guided-actions .button { min-width: 0; }
.celebration { justify-items: center; text-align: center; }
.celebration .list-row { width: 100%; text-align: left; }
.celebration-mascot { width: 112px; height: 112px; border-radius: 50%; object-fit: cover; animation: mascot-pop .6s ease-out; }
.model-list { max-height: 50vh; overflow-y: auto; }
.model-item { align-items: flex-start; padding: 6px 0; }
.model-item > span { display: grid; gap: 2px; min-width: 0; }
.model-changes { overflow-wrap: anywhere; }
@keyframes mascot-pop {
  0% { transform: scale(.4) rotate(-12deg); opacity: 0; }
  70% { transform: scale(1.12) rotate(4deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}

/* Amministrazione */
.admin-text { min-width: 0; overflow-wrap: anywhere; }
.list-row.wrap { flex-wrap: wrap; }
.field textarea.phrases { min-height: 240px; }

.chart { display: block; width: 100%; height: auto; }
.chart-line { fill: none; stroke: var(--monthly-end); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.chart-grid { stroke: #eef1ed; stroke-width: 1; }
.chart-point { fill: var(--monthly-end); }
.chart-label { fill: var(--muted); font-size: 12px; font-weight: 600; }

.empty { display: grid; justify-items: center; gap: 10px; padding: 34px 16px; color: var(--muted); font-weight: 600; text-align: center; }
.empty img { width: 92px; height: 92px; border-radius: 50%; object-fit: cover; }
.loading { padding: 40px; color: var(--muted); font-weight: 700; text-align: center; }

.toast { position: fixed; z-index: 50; left: 50%; bottom: 24px; max-width: min(92vw, 460px); padding: 12px 16px; border-radius: 13px; background: var(--navy); color: #fff; font-size: .9rem; font-weight: 700; transform: translateX(-50%); opacity: 0; pointer-events: none; transition: opacity .2s; }
.toast.visible { opacity: 1; }

dialog { width: min(92vw, 460px); padding: 22px; border: 0; border-radius: 24px; color: var(--ink); }
dialog::backdrop { background: rgba(17, 24, 39, .55); }
dialog h2 { margin-bottom: 12px; }
dialog .row { margin-top: 18px; }

@media (max-width: 820px) {
  .login { padding: 0; place-items: stretch; }
  .login-shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; border-radius: 0; box-shadow: none; }
  .login-visual { order: -1; min-height: 0; height: 38vh; }
  .shell { display: block; }
  .sidebar { display: none; }
  .main { padding: 16px 16px 96px; }
  .mobile-nav {
    position: fixed; z-index: 20; left: 0; right: 0; bottom: 0;
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 2px;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    border-radius: 22px 22px 0 0;
    background: linear-gradient(145deg, var(--monthly-start), var(--monthly-end));
  }
  .mobile-nav .nav-link { justify-content: center; min-height: 48px; padding: 0 1px; font-size: .68rem; letter-spacing: -.01em; text-align: center; background: transparent; }
  .mobile-only { display: inline-flex; }
  .mobile-nav .nav-link.active { background: rgba(255, 255, 255, .16); }
  .day { min-height: 64px; padding: 4px; border-radius: 10px; }
  .event { padding: 2px 3px; font-size: .62rem; }
  /* Nelle celle strette del mese il titolo serve più dell'ora, che resta nella vista settimana. */
  .calendar.month .event-time { display: none; }
  .chart-label { font-size: 22px; }
  .calendar { gap: 3px; }
  .calendar.week { grid-template-columns: 1fr; }
  .calendar.week .calendar-head { display: none; }
  .calendar.week .day { min-height: 60px; }
  .hero > img { object-position: 82% 30%; }
  .toast { bottom: 96px; }
}

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

.avatar-row { display: flex; align-items: center; gap: 14px; }
.avatar-preview { flex: none; width: 76px; height: 76px; border-radius: 50%; object-fit: cover; }
.avatar-crop { display: block; width: min(100%, 280px); height: auto; aspect-ratio: 1; margin-inline: auto; border-radius: 50%; background: #f4f7f3; touch-action: none; cursor: grab; }
.menu-user { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid rgba(255, 255, 255, .25); color: #fff; }
.menu-user img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
