:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #5b6678;
  --line: #dde3ec;
  --brand: #0369a1;
  --on-brand: #ffffff;
  --luca: #1d4ed8;
  --barbara: #c2410c;
  --danger: #b91c1c;
  --top: #0f172a;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a101e;
    --card: #131c31;
    --text: #e6eaf3;
    --muted: #9aa6bb;
    --line: #26324b;
    --brand: #38bdf8;
    --on-brand: #04263a;
    --luca: #7ab0ff;
    --barbara: #fb9a5c;
    --danger: #f87171;
    --top: #060b17;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2 { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* ----- splash / login ----- */
#splash { min-height: 100vh; display: grid; place-items: center; color: var(--muted); }
#login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: min(100%, 380px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  display: grid;
  gap: 14px;
}
.login-card h1 { font-size: 22px; }
.login-card p { margin: 0; }

/* ----- campi ----- */
label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
input:not([type="radio"]), select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  font-size: 16px; /* evita lo zoom automatico su iPhone */
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent);
  outline-offset: 1px;
}
.err { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }
.hint { color: var(--muted); font-size: 14px; min-height: 1.2em; margin: 0; }

button.primary {
  min-height: 46px;
  padding: 0 20px;
  border: 0;
  border-radius: 10px;
  background: var(--brand);
  color: var(--on-brand);
  font-weight: 600;
}
button.primary.big { width: 100%; min-height: 52px; font-size: 17px; }
button.primary:disabled { opacity: .6; }
button.ghost {
  background: transparent; border: 1px solid rgba(255, 255, 255, .35);
  color: #fff; border-radius: 8px; min-height: 36px; padding: 0 12px;
}
button.danger {
  min-height: 46px; padding: 0 14px; border-radius: 10px;
  background: transparent; border: 1px solid var(--danger); color: var(--danger);
}
.actions button:not(.primary):not(.danger) {
  min-height: 46px; padding: 0 14px; border-radius: 10px;
  background: transparent; border: 1px solid var(--line);
}

/* ----- barra alta ----- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--top); color: #fff;
}
.top h1 { font-size: 18px; flex: 1; }
.net { background: #b45309; color: #fff; border-radius: 99px; padding: 2px 10px; font-size: 13px; }
.banner { margin: 0; padding: 10px 14px; background: #fef3c7; color: #78350f; font-size: 14px; }

main { max-width: 640px; margin: 0 auto; padding: 14px 12px calc(96px + env(safe-area-inset-bottom)); }
section > form, #addForm { display: grid; gap: 12px; }
.sec { font-size: 15px; color: var(--muted); margin: 22px 2px 8px; font-weight: 600; }

/* ----- scelta attrezzo ----- */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span {
  display: grid; place-items: center; min-height: 44px; text-align: center;
  padding: 4px 6px; font-size: 14px; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
}
.seg input:checked + span { background: var(--brand); color: var(--on-brand); border-color: var(--brand); font-weight: 600; }
.seg input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); }

/* ----- colonne Luca / Barbara ----- */
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cols.one { grid-template-columns: 1fr; }
.pcol {
  margin: 0; min-width: 0; display: grid; gap: 8px;
  padding: 10px; border: 2px solid var(--line); border-radius: var(--radius); background: var(--card);
}
.pcol legend { padding: 0 6px; font-weight: 700; }
.pcol.luca { border-color: var(--luca); }
.pcol.luca legend { color: var(--luca); }
.pcol.barbara { border-color: var(--barbara); }
.pcol.barbara legend { color: var(--barbara); }
.pcol .last { margin: 0; font-size: 13px; color: var(--muted); min-height: 1.2em; }

/* ----- schede ----- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 10px;
}
.card > header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.link { background: none; border: 0; padding: 0; font-weight: 700; font-size: 17px; text-align: left; color: var(--text); }
.badge {
  font-size: 12px; padding: 2px 8px; border-radius: 99px;
  background: color-mix(in srgb, var(--brand) 16%, transparent); color: var(--brand);
}
.cell { min-width: 0; padding-left: 8px; border-left: 4px solid var(--line); display: grid; align-content: start; gap: 2px; }
.cell.luca { border-left-color: var(--luca); }
.cell.barbara { border-left-color: var(--barbara); }
.cell .who { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.cell.luca .who { color: var(--luca); }
.cell.barbara .who { color: var(--barbara); }
.cell .none { color: var(--muted); padding: 6px 0; }
.entry {
  text-align: left; background: transparent; border: 0; border-radius: 8px;
  padding: 7px 6px; margin: 0 -6px; min-height: 40px; font-size: 16px;
}
.entry:active { background: color-mix(in srgb, var(--brand) 14%, transparent); }

/* ----- elenco esercizi ----- */
#exSearch { margin-bottom: 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 38px; padding: 0 14px; border-radius: 99px;
  background: var(--card); border: 1px solid var(--line); font-size: 15px;
}
.chip[aria-pressed="true"] { background: var(--brand); color: var(--on-brand); border-color: var(--brand); font-weight: 600; }
.chip small { opacity: .7; margin-left: 4px; }
.exitem {
  width: 100%; text-align: left; display: grid; grid-template-columns: 1fr auto 20px; gap: 2px 8px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 8px;
}
.exitem .name { font-weight: 600; }
.exitem .meta { grid-column: 1 / 3; font-size: 13px; color: var(--muted); }
.exitem .chev { grid-row: 1 / 3; grid-column: 3; color: var(--muted); font-size: 22px; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }

/* ----- dettaglio esercizio ----- */
.detailhead { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.detailhead h2 { font-size: 21px; flex: 1 1 100%; }
.back { background: none; border: 0; color: var(--brand); font-weight: 600; padding: 6px 0; min-height: 40px; }
.smallbtn { min-height: 36px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); }
.records { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.rec { padding: 10px 12px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--line); }
.rec.luca { border-left-color: var(--luca); }
.rec.barbara { border-left-color: var(--barbara); }
.rec span { display: block; font-size: 12px; color: var(--muted); }
.rec strong { font-size: 19px; }
.rec small { display: block; color: var(--muted); }

/* ----- per data ----- */
.datebar { display: grid; grid-template-columns: 46px 1fr 46px auto; gap: 8px; margin-bottom: 12px; }
.datebar button {
  min-height: 46px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); font-size: 22px; line-height: 1;
}
.datebar .ghost-dark { font-size: 15px; padding: 0 14px; }
.summary { display: flex; gap: 14px; flex-wrap: wrap; margin: 0 2px 10px; font-size: 14px; color: var(--muted); }
.summary b.luca { color: var(--luca); }
.summary b.barbara { color: var(--barbara); }

/* ----- barra in basso ----- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs button {
  display: grid; justify-items: center; gap: 2px; padding: 8px 4px 7px;
  background: none; border: 0; color: var(--muted); font-size: 12px; min-height: 58px;
}
.tabs button[aria-current="page"] { color: var(--brand); font-weight: 700; }
.tabs svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ----- finestre ----- */
dialog {
  width: min(92vw, 440px); max-height: 92vh; overflow: auto;
  border: 0; border-radius: 16px; padding: 18px;
  background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog form { display: grid; gap: 12px; }
dialog h2 { font-size: 19px; }
.row3 { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; }
.actions { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }

#toast {
  position: fixed; left: 50%; bottom: calc(78px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 99px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: #b91c1c; }

@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
