/* =============================================================================
   Garmin AI Coach PWA - tema scuro, mobile-first
   ============================================================================= */
:root {
  --bg: #0e1117;
  --bg-soft: #161b24;
  --card: #1b2230;
  --card-2: #212a3a;
  --border: #2b3648;
  --text: #e6eaf2;
  --text-dim: #8b95a7;
  --accent: #4f8cff;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 16px;
  --nav-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px); }

/* ---------- header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  /* safe-area-inset-top: su iPhone con notch il contenuto dell'header
     (titolo + badge Readiness) scenderebbe sotto l'orologio/notch. */
  padding: calc(12px + var(--safe-top)) 16px calc(10px + var(--safe-bottom) * 0.3);
  background: rgba(14, 17, 23, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-brand { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 26px; }
.app-header h1 { font-size: 17px; font-weight: 700; letter-spacing: .2px; }
.header-sub { font-size: 11.5px; color: var(--text-dim); }

.pill {
  font-size: 12px; font-weight: 700; padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--border);
}
.pill-green { background: rgba(34,197,94,.15); color: var(--green); border-color: rgba(34,197,94,.4); }
.pill-amber { background: rgba(245,158,11,.15); color: var(--amber); border-color: rgba(245,158,11,.4); }
.pill-red   { background: rgba(239,68,68,.15);  color: var(--red);   border-color: rgba(239,68,68,.4); }
.pill-neutral { color: var(--text-dim); }

/* ---------- main / tabs ---------- */
main { max-width: 560px; margin: 0 auto; padding: 16px 14px; }
.tab { display: none; animation: fadeIn .25s ease; }
.tab.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 { font-size: 16px; margin-bottom: 10px; }
.card h3 { font-size: 14px; margin-bottom: 8px; color: var(--text-dim); }

.hidden { display: none !important; }
.hint { font-size: 12px; color: var(--text-dim); margin: 6px 0; }

/* ---------- buttons ---------- */
.btn {
  border: none; border-radius: 12px; padding: 12px 16px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  color: var(--text); background: var(--card-2);
  transition: filter .15s, transform .05s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; margin-top: 10px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-warn { background: var(--amber); color: #111; }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
.spin {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.3); border-top-color: #fff;
  animation: rot .7s linear infinite;
}
@keyframes rot { to { transform: rotate(360deg); } }

/* ---------- readiness gauge ---------- */
.readiness-card { display: flex; flex-direction: column; align-items: center; padding: 10px 0 4px; }
.gauge-wrap { position: relative; }
.gauge-track { fill: none; stroke: var(--border); stroke-width: 14; }
.gauge-arc {
  fill: none; stroke-width: 14; stroke-linecap: round;
  transform: rotate(-90deg); transform-origin: 100px 100px;
  transition: stroke-dasharray .8s cubic-bezier(.4,0,.2,1);
}
.gauge-value { font-size: 44px; font-weight: 800; fill: var(--text); text-anchor: middle; }
.gauge-label { font-size: 13px; fill: var(--text-dim); text-anchor: middle; }
.readiness-meta { display: flex; gap: 14px; margin-top: 12px; font-size: 12.5px; color: var(--text-dim); }
.readiness-meta b { color: var(--text); display: block; font-size: 15px; }

.comp-row { display: flex; align-items: center; gap: 10px; margin: 9px 0; font-size: 13px; }
.comp-row .comp-name { width: 74px; color: var(--text-dim); flex-shrink: 0; }
.comp-bar { flex: 1; height: 8px; border-radius: 99px; background: var(--bg-soft); overflow: hidden; }
.comp-bar i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .6s; }
.comp-row .comp-val { width: 38px; text-align: right; font-weight: 700; }

.meta-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.meta-cell { background: var(--bg-soft); border-radius: 12px; padding: 10px 8px; text-align: center; }
.meta-cell .v { font-size: 15px; font-weight: 700; }
.meta-cell .k { font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .4px; }

.act-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 0; border-bottom: 1px dashed var(--border); font-size: 13px;
}
.act-row:last-child { border-bottom: none; }
.act-row .tag {
  font-size: 10px; padding: 2px 8px; border-radius: 99px; background: var(--card-2);
  color: var(--accent); font-weight: 700;
}

/* ---------- workout ---------- */
textarea, input[type="text"], input[type="number"] {
  width: 100%; background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 11px 12px; font-size: 14px; font-family: inherit;
}
textarea { resize: vertical; }
textarea:focus, input:focus { outline: none; border-color: var(--accent); }
.toggle-row { display: flex; align-items: center; gap: 9px; margin-top: 10px; font-size: 13px; color: var(--text-dim); cursor: pointer; }
.toggle-row input { width: 17px; height: 17px; accent-color: var(--amber); }

.workout-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.workout-head h3 { font-size: 15px; color: var(--text); margin: 0; }
.phase { border-left: 3px solid var(--accent); padding: 8px 10px; margin: 8px 0; background: var(--bg-soft); border-radius: 0 10px 10px 0; font-size: 13px; }
.phase .p-tag { font-weight: 700; color: var(--accent); text-transform: uppercase; font-size: 11px; }
.phase .p-detail { color: var(--text-dim); font-size: 12px; }
.sync-ok { color: var(--green); font-weight: 700; }
.sync-err { color: var(--red); font-weight: 600; }

/* ---------- body map (infortuni) ---------- */
.body-map { display: flex; gap: 10px; margin-top: 10px; }
.body-view { flex: 1; text-align: center; }
.body-view h3 { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.body-svg svg { width: 100%; height: auto; max-width: 190px; }
.body-part { cursor: pointer; transition: fill .15s, opacity .15s; }
.body-part:hover { opacity: .8; }
.body-sil { fill: var(--bg-soft); stroke: var(--border); stroke-width: 1.6; }
.body-part { fill: rgba(79,140,255,.10); stroke: rgba(120,150,200,.45); stroke-width: 1.3; }
.body-part.inj { stroke: #fff; stroke-width: 2; }
/* Punti neon: bagliore colorato in base alla severita */
.body-part.inj.inj-1,
.body-part.inj.inj-2 { filter: drop-shadow(0 0 5px rgba(250,204,21,.9)); }
.body-part.inj.inj-3 { filter: drop-shadow(0 0 6px rgba(249,115,22,.95)); }
.body-part.inj.inj-4 { filter: drop-shadow(0 0 7px rgba(239,68,68,1)); }
.body-part.inj.inj-5 { filter: drop-shadow(0 0 8px rgba(239,68,68,1)); }
.inj-1 { fill: rgba(250,204,21,.45); }
.inj-2 { fill: rgba(250,204,21,.60); }
.inj-3 { fill: rgba(249,115,22,.55); }
.inj-4 { fill: rgba(239,68,68,.55); }
.inj-5 { fill: rgba(239,68,68,.75); }
.legend { display: flex; justify-content: center; gap: 14px; font-size: 11px; color: var(--text-dim); margin-top: 10px; flex-wrap: wrap; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.dot-1 { background: #facc15; } .dot-3 { background: #f97316; } .dot-4 { background: #ef4444; }

.injury-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 0;
  border-bottom: 1px dashed var(--border); font-size: 13.5px;
}
.injury-item:last-child { border-bottom: none; }
.injury-item .sev { width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-weight: 800; color: #fff; flex-shrink: 0; }
.injury-item .inf { flex: 1; }
.injury-item .inf b { font-size: 14px; }
.injury-item .inf small { display: block; color: var(--text-dim); }
.injury-item .resolved { text-decoration: line-through; opacity: .55; }
.injury-item .del { background: none; border: none; font-size: 18px; cursor: pointer; padding: 6px; color: var(--red); }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-box {
  width: 100%; max-width: 480px; background: var(--card);
  border-radius: 22px 22px 0 0; padding: 20px 18px calc(22px + var(--safe-bottom));
  border: 1px solid var(--border); border-bottom: none;
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.severity-picker { display: flex; gap: 8px; margin: 8px 0 12px; }
.severity-picker button {
  flex: 1; height: 40px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-soft); color: var(--text); font-weight: 700; font-size: 14px; cursor: pointer;
}
.severity-picker button.sel { background: var(--accent); border-color: var(--accent); color: #fff; }
.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }

/* ---------- goals ---------- */
.segmented { display: flex; background: var(--bg-soft); border-radius: 12px; padding: 4px; margin: 10px 0; }
.seg-btn { flex: 1; border: none; background: transparent; color: var(--text-dim); padding: 10px; border-radius: 9px; font-weight: 700; font-size: 14px; cursor: pointer; }
.seg-btn.sel { background: var(--accent); color: #fff; }
.time-inputs { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.time-inputs input { text-align: center; font-size: 22px; font-weight: 700; padding: 10px 6px; }
.time-inputs span { font-size: 22px; color: var(--text-dim); font-weight: 700; }
.goal-result { margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--bg-soft); font-size: 13px; text-align: center; }
.goal-result b { font-size: 18px; color: var(--green); }
.threshold-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.th-item { background: var(--bg-soft); border-radius: 12px; padding: 10px 4px; text-align: center; }
.th-val { display: block; font-size: 17px; font-weight: 800; color: var(--accent); }
.th-lab { font-size: 9.5px; color: var(--text-dim); }

/* ---------- chat ---------- */
.tab-chat { display: flex; flex-direction: column; }
.chat-log { display: flex; flex-direction: column; gap: 8px; padding: 6px 0 10px; }
.bubble { max-width: 84%; padding: 10px 13px; border-radius: 16px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.bubble.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.bubble.coach { align-self: flex-start; background: var(--card-2); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.bubble.workout { align-self: flex-start; background: var(--card); border: 1px solid var(--accent); border-bottom-left-radius: 5px; max-width: 94%; font-size: 13px; }
.bubble.warn { align-self: flex-start; background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.5); color: #fca5a5; border-bottom-left-radius: 5px; }
.chat-actions { display: flex; gap: 8px; margin-bottom: 8px; }
.chat-actions .btn { flex: 1; font-size: 12.5px; padding: 10px 8px; }
.chat-input-row { display: flex; gap: 8px; position: sticky; bottom: calc(var(--nav-h) + var(--safe-bottom)); background: var(--bg); padding: 8px 0; }
.chat-input-row input { flex: 1; }
.chat-input-row .btn { width: 46px; padding: 0; }

/* ---------- login screen (API Key) ---------- */
.login-screen {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-box {
  width: 100%; max-width: 360px; background: var(--card);
  border: 1px solid var(--border); border-radius: 22px;
  padding: 28px 22px; text-align: center;
}
.login-logo { font-size: 44px; margin-bottom: 8px; }
.login-box h2 { font-size: 19px; margin-bottom: 6px; }
.login-box p { font-size: 13px; color: var(--text-dim); margin-bottom: 16px; }
.login-box input { margin-bottom: 12px; text-align: center; letter-spacing: .5px; }
.login-err { color: var(--red); font-size: 13px; margin-top: 10px; font-weight: 600; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 26px);
  transform: translateX(-50%); z-index: 60;
  background: var(--card-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 18px; border-radius: 999px; font-size: 13px; font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
  animation: fadeIn .2s ease;
}

/* ---------- bottom nav ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  background: rgba(14,17,23,.95); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  height: calc(var(--nav-h) + var(--safe-bottom));
}
.nav-btn {
  flex: 1; background: none; border: none; color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 10px; font-weight: 600; cursor: pointer; padding: 4px 0;
}
.nav-btn .nav-ico { font-size: 20px; filter: grayscale(.5); opacity: .8; }
.nav-btn.active { color: var(--accent); }
.nav-btn.active .nav-ico { filter: none; opacity: 1; }
