/* Training Michaela — mobile-first, large tap targets */
:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --ok: #16a34a;
  --danger: #dc2626;
  --warn: #d97706;
  --border: #e2e8f0;
  --radius: 12px;
  --tap: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
body { min-height: 100dvh; }

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(32px + var(--safe-bottom));
}

h1 { font-size: 1.35rem; margin: 0 0 8px; }
h2 { font-size: 1.1rem; margin: 0 0 8px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); font-size: 0.9rem; }
.disclaimer { font-size: 0.85rem; background: #fff7ed; border: 1px solid #fed7aa; border-radius: var(--radius); padding: 10px; }

.screen { display: none; }
.screen.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.resume-banner { border-color: #93c5fd; background: #eff6ff; }

.exercise-preview {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.exercise-preview img {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  background: #e8f0fe;
  flex-shrink: 0;
}
.exercise-preview .meta { flex: 1; min-width: 0; }
.exercise-preview .name { font-weight: 600; }
.exercise-preview .detail { color: var(--muted); font-size: 0.85rem; }
.exercise-preview .actions { flex-shrink: 0; }
.exercise-preview .actions button {
  width: auto;
  min-height: 40px;
  padding: 8px 12px;
  font-size: 0.85rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.chip {
  display: inline-block;
  background: #e0e7ff;
  color: #3730a3;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.btn-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}
.btn-row.inline {
  flex-direction: row;
  margin-top: 8px;
}
.btn-row.inline button { flex: 1; }

button, .btn, input[type="text"], input[type="number"], textarea {
  font-family: inherit;
}
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 12px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-danger { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }

.pain-scale {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  gap: 4px;
  margin: 12px 0 16px;
}
.pain-scale button {
  min-height: 40px;
  padding: 0;
  font-size: 0.85rem;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  width: 100%;
  border-radius: 8px;
}
.pain-scale button.selected {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.exercise-active img {
  width: 100%;
  max-height: 180px;
  object-fit: contain;
  border-radius: var(--radius);
  background: #e8f0fe;
  margin: 8px 0 12px;
}
.dose-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.badge {
  display: inline-block;
  background: #e0e7ff;
  color: #3730a3;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}
.countdown {
  font-size: 3.5rem;
  font-weight: 700;
  text-align: center;
  margin: 20px 0;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  color: var(--primary);
}
.progress {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}
.history-item .pain { font-weight: 600; white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }

.top-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.top-bar .back {
  width: auto;
  min-height: 40px;
  padding: 8px 12px;
  flex-shrink: 0;
}

.plan-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.plan-item .row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.plan-item .row .meta { flex: 1; min-width: 0; }
.plan-item .name { font-weight: 600; }
.plan-item.inactive { opacity: 0.55; }
.plan-item .mini-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.plan-item .mini-btns button {
  width: auto;
  min-height: 40px;
  padding: 8px 10px;
  font-size: 0.85rem;
  flex: 1;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}
.field-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
  margin: 8px 0 4px;
}
input[type="text"],
input[type="number"],
textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 80px; resize: vertical; }
.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
  font-weight: 600;
  min-height: var(--tap);
}
.check-row input { width: 22px; height: 22px; }

.swap-option {
  cursor: pointer;
}
.swap-option:active { background: #eff6ff; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  z-index: 50;
}
.modal[hidden] { display: none !important; }
.modal-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 18px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
}

.chat-messages {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 220px;
  max-height: 45dvh;
  overflow-y: auto;
  margin-bottom: 12px;
}
.chat-bubble {
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-bubble.user {
  background: #dbeafe;
  margin-left: 24px;
}
.chat-bubble.assistant {
  background: #f1f5f9;
  margin-right: 24px;
}
.chat-bubble.system {
  background: #fff7ed;
  font-size: 0.85rem;
  color: #9a3412;
}
.chat-compose {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
