/* Pannello Coach — stessa palette dell'app Android (navy + verde lime). */
:root {
  --bg: #0b1520;
  --navy: #0e1a28;
  --surface: #162638;
  --surface-2: #1d3047;
  --line: #24384f;
  --text: #f4f7fa;
  --muted: #8a99ab;
  --green: #8eff3b;
  --green-dark: #66cc1a;
  --green-soft: rgba(142, 255, 59, 0.14);
  --red: #ff4d4f;
  --amber: #ffb547;
  --radius: 16px;
  --radius-sm: 10px;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--green); font-weight: 800; }
h3 { font-size: 16px; font-weight: 700; }
p { margin: 0; }
svg { fill: currentColor; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 700; }

/* ---------- Layout ---------- */
.shell { display: none; min-height: 100vh; }
body.authed .shell { display: grid; grid-template-columns: 240px 1fr; }
body.authed .login { display: none; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: var(--navy); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 20px 14px; gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand strong { display: block; font-size: 15px; }
.brand span:not(.logo) { display: block; font-size: 12px; color: var(--muted); }
.logo {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: var(--green); color: var(--navy); font-weight: 900; font-size: 18px; flex: none;
}
.brand.big .logo { width: 48px; height: 48px; font-size: 24px; border-radius: 14px; }
.brand.big strong { font-size: 18px; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 600;
}
.nav a svg { width: 20px; height: 20px; }
.nav a:hover { background: var(--surface); color: var(--text); }
.nav a.active { background: var(--green-soft); color: var(--green); }

.me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px 6px 0; border-top: 1px solid var(--line); }
.me-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { padding: 32px 40px 64px; max-width: 1240px; width: 100%; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head .grow { flex: 1; min-width: 200px; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.back:hover { color: var(--text); }

/* ---------- Card & griglie ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h2 { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

.kpi { background: var(--surface); border-radius: var(--radius); padding: 16px 18px; }
.kpi .v { font-size: 26px; font-weight: 800; margin-top: 4px; }
.kpi .h { color: var(--muted); font-size: 12px; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; font-weight: 600; }

/* ---------- Clienti ---------- */
.search { position: relative; }
.search input { padding-left: 36px; width: 280px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }

.client-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.client-card {
  background: var(--surface); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 14px;
  border: 1px solid transparent; transition: border-color 0.15s, transform 0.15s;
}
.client-card:hover { border-color: var(--line); transform: translateY(-1px); }
.client-card .top { display: flex; align-items: center; gap: 12px; }
.client-card .name { font-weight: 700; font-size: 16px; }
.client-card .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.client-card .stat { background: var(--navy); border-radius: var(--radius-sm); padding: 8px 10px; }
.client-card .stat b { display: block; font-size: 16px; }
.client-card .stat span { font-size: 11px; color: var(--muted); }

.avatar {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--surface-2); color: var(--green); font-weight: 800;
}
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: rgba(255, 181, 71, 0.14); color: var(--amber); }
.badge.red { background: rgba(255, 77, 79, 0.14); color: var(--red); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); display: inline-block; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; background: var(--surface); padding: 4px; border-radius: 999px; width: fit-content; margin-bottom: 20px; }
.tabs a { padding: 8px 18px; border-radius: 999px; color: var(--muted); font-weight: 600; }
.tabs a:hover { color: var(--text); }
.tabs a.active { background: var(--green); color: var(--navy); }

/* ---------- Tabelle / liste ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; padding: 0 10px 10px; }
td { padding: 10px; border-top: 1px solid var(--line); vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
.list-item { display: flex; align-items: center; gap: 12px; background: var(--navy); border-radius: var(--radius-sm); padding: 12px 14px; }

/* ---------- Form ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--navy); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 11px; outline: none; min-width: 0;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { border-color: var(--green); }
input[type="number"] { -moz-appearance: textfield; }
.form-error { color: var(--red); font-size: 13px; }

.btn {
  font: inherit; font-weight: 700; cursor: pointer; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text); padding: 9px 16px; border-radius: var(--radius-sm); display: inline-flex; align-items: center; gap: 8px;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--green); color: var(--navy); border-color: var(--green); }
.btn.primary:hover { background: var(--green-dark); border-color: var(--green-dark); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; padding: 12px; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { background: none; border: none; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; display: grid; place-items: center; }
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn.danger:hover { color: var(--red); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(circle at 20% 10%, rgba(142, 255, 59, 0.08), transparent 40%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 20px; padding: 32px; display: flex; flex-direction: column; gap: 16px; }
.login-card .brand { margin-bottom: 8px; padding: 0; }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; height: min(640px, calc(100vh - 260px)); background: var(--surface); border-radius: var(--radius); }
.chat-log { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 70%; padding: 10px 14px; border-radius: 16px; background: var(--surface-2); white-space: pre-wrap; word-wrap: break-word; }
.bubble.mine { align-self: flex-end; background: var(--green); color: var(--navy); border-bottom-right-radius: 4px; }
.bubble.theirs { align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble time { display: block; font-size: 10px; opacity: 0.65; margin-top: 4px; }
.bubble.system { align-self: center; max-width: 85%; background: var(--green-soft); border: 1px solid rgba(142, 255, 59, 0.3); text-align: center; }
.bubble.system .eyebrow { display: block; color: var(--green); margin-bottom: 4px; }
.chat-day { align-self: center; font-size: 11px; color: var(--muted); padding: 6px 0; }
.chat-form { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--line); }
.chat-form textarea { flex: 1; min-height: 44px; max-height: 140px; resize: none; }

/* ---------- Grafici ---------- */
.chart { width: 100%; height: 200px; display: block; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }

/* ---------- Editor schede ---------- */
.day { background: var(--surface); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; }
.day-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; background: var(--surface-2); }
.day-head .num { width: 30px; height: 30px; border-radius: 8px; background: var(--green); color: var(--navy); display: grid; place-items: center; font-weight: 800; flex: none; }
.day-head input.title { flex: 1; font-weight: 700; font-size: 15px; background: transparent; border-color: transparent; }
.day-head input.title:hover, .day-head input.title:focus { border-color: var(--line); background: var(--navy); }
.day-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.block { border: 1px solid var(--line); border-radius: var(--radius-sm); }
.block-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.block-head select { padding: 5px 8px; font-size: 12px; }
.block-head .label { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.ex-row { display: grid; grid-template-columns: minmax(180px, 2.2fr) 64px 90px 100px 80px 64px 80px auto; gap: 8px; align-items: end; padding: 10px 12px; }
.ex-row + .ex-row { border-top: 1px dashed var(--line); }
.ex-row label { font-size: 10px; }
.ex-row input, .ex-row select { padding: 7px 8px; font-size: 13px; }
.ex-row .notes { grid-column: 1 / -2; }
.ex-actions { display: flex; gap: 2px; align-self: center; }
.sticky-bar {
  position: sticky; bottom: 16px; margin-top: 24px; display: flex; align-items: center; gap: 12px;
  background: var(--navy); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}

/* ---------- Anteprima esercizio ---------- */
.ex-thumb { position: relative; display: inline-block; flex: none; border-radius: 10px; overflow: hidden; background: #fff; vertical-align: middle; }
.ex-thumb.empty { background: var(--surface-2); }
.ex-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ex-thumb.anim img:last-child { animation: ex-frame 1.6s steps(1) infinite; }
@keyframes ex-frame { 0% { opacity: 0; } 50% { opacity: 1; } }
.ex-preview { display: flex; gap: 14px; align-items: center; }

/* ---------- Varie ---------- */
.loading { display: grid; place-items: center; padding: 80px 0; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: var(--green); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 14px; }
.empty h3 { color: var(--text); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--surface-2); color: var(--text); padding: 12px 18px; border-radius: 12px; font-weight: 600;
  border-left: 4px solid var(--green); transition: all 0.2s; z-index: 50; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-left-color: var(--red); }

dialog { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 18px; padding: 24px; width: min(560px, 92vw); }
dialog::backdrop { background: rgba(5, 10, 16, 0.7); }
dialog form { display: flex; flex-direction: column; gap: 14px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

@media (max-width: 960px) {
  body.authed .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; padding: 12px; }
  .sidebar .brand span:not(.logo), .me-name { display: none; }
  .nav { flex-direction: row; }
  .me { margin: 0 0 0 auto; border: none; padding: 0; }
  .main { padding: 20px 16px 48px; }
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr 1fr; }
  .ex-row { grid-template-columns: 1fr 1fr 1fr; }
  .ex-row .notes { grid-column: 1 / -1; }
}

/* ---------- Telefono ---------- */
@media (max-width: 640px) {
  body { font-size: 15px; }
  h1 { font-size: 22px; }
  body.authed .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar, .main { min-width: 0; }
  .sidebar { gap: 10px; padding: 10px 12px; position: sticky; top: 0; z-index: 20; }
  .sidebar .brand strong { display: none; }
  .nav { flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; gap: 2px; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 8px 10px; gap: 6px; white-space: nowrap; font-size: 13px; }
  .main { padding: 16px 12px 96px; }
  .page-head { margin-bottom: 16px; }
  .page-head .grow { min-width: 0; flex-basis: 100%; }
  .card { padding: 14px; }
  .card-head { flex-wrap: wrap; }
  .card-head h2 { min-width: 0; overflow-wrap: anywhere; }
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: minmax(0, 1fr); }
  .client-list { grid-template-columns: minmax(0, 1fr); }
  .search, .search input { width: 100%; }
  .tabs { width: auto; max-width: 100%; overflow-x: auto; }
  .tabs a { padding: 8px 12px; white-space: nowrap; }
  table { display: block; overflow-x: auto; }
  .bubble { max-width: 85%; }
  .chat { height: calc(100vh - 200px); }
  input, select, textarea { font-size: 16px; } /* niente zoom automatico su iPhone */

  /* Editor scheda */
  .day-head { padding: 10px 12px; gap: 4px; }
  .day-body { padding: 12px 10px; }
  .block-head { flex-wrap: wrap; padding: 8px 10px; }
  .ex-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding: 10px; }
  .ex-row > .row:first-child { grid-column: 1 / -1; }
  .ex-row .ex-actions { grid-column: 1 / -1; justify-content: flex-end; order: 10; }
  .ex-row input, .ex-row select { font-size: 16px; padding: 8px; }
  .ex-row label { font-size: 11px; }
  .day-body > .row.wrap > input { min-width: 0 !important; max-width: none !important; flex-basis: 100% !important; }
  .bulk-row input { flex: 1; width: auto !important; min-width: 70px; }
  .sticky-bar { position: static; flex-wrap: wrap; gap: 8px; padding: 10px; }
  .block-head .spacer { display: none; }
  .block-head [data-add-to-block] { margin-left: auto; }
  .sticky-bar #save-state { flex-basis: 100%; }
  .sticky-bar .spacer { display: none; }
  .sticky-bar .btn { flex: 1; justify-content: center; padding: 10px 8px; }
  .client-strip { font-size: 12px; padding: 10px 12px; }
  .video-dlg { padding: 12px; }
  dialog { padding: 16px; }
}

/* ---------- Foto luogo di allenamento ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin-top: 14px; }
.photo-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-sm); display: block; }
.photo-grid a:hover img { outline: 2px solid var(--green); }
.photo-grid.tall img { aspect-ratio: 3 / 4; }
.photo-grid a { display: flex; flex-direction: column; gap: 4px; text-align: center; }

/* ---------- Allegati in chat ---------- */
.bubble.media { padding: 6px; }
.chat-img { display: block; max-width: 260px; max-height: 320px; border-radius: 12px; }
.chat-video { display: block; max-width: 300px; border-radius: 12px; }
.bubble audio { display: block; max-width: 260px; }
.chat-form .icon-btn { align-self: center; }
#chat-mic.recording { color: var(--red); background: rgba(255, 77, 79, 0.15); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* ---------- Editor: riepilogo cliente e azioni rapide ---------- */
.client-strip { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; background: var(--surface); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; font-size: 13px; }
.bulk-row { background: var(--navy); border-radius: var(--radius-sm); padding: 8px 10px; }
.bulk-row input { padding: 6px 8px; font-size: 13px; }

/* Pagina Video */
.video-card { padding: 12px; }
.video-box { position: relative; aspect-ratio: 16 / 9; width: 100%; margin: 0 auto 10px; background: var(--surface-2); border-radius: 10px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.video-dlg { width: min(720px, 94vw); background: var(--surface); color: inherit; border: 1px solid var(--border, #2a3444); border-radius: 14px; padding: 16px; }
.video-dlg::backdrop { background: rgba(0, 0, 0, .6); }
.video-mini { width: 40px; height: 40px; flex: none; border: 0; border-radius: 10px; background: var(--green); color: #0b1220; font-size: 16px; cursor: pointer; }
.video-box video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.video-play { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--green); color: var(--navy); font-size: 22px; cursor: pointer; }
.video-num { position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 6px; }
.video-title { width: 100%; font-weight: 600; }
select.sm, input.sm { padding: 5px 8px; font-size: 12px; }
button.badge { border: 0; cursor: pointer; }
.chip { display: inline-flex; align-items: center; gap: 4px; margin: 3px 4px 0 0; padding: 2px 4px 2px 8px; border-radius: 12px; background: var(--green-soft); color: var(--green); font-size: 12px; }
.chip button { border: 0; background: none; color: inherit; cursor: pointer; font-size: 14px; line-height: 1; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--green); transition: width .3s; }
