:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --text: var(--tg-theme-text-color, #1c1c1e);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #3a86d4);
  --green: #2e9e57;
  --blue: #3a86d4;
  --orange: #e08a00;
  --red: #d64545;
  --green-bg: rgba(46, 158, 87, 0.14);
  --blue-bg: rgba(58, 134, 212, 0.14);
  --orange-bg: rgba(224, 138, 0, 0.16);
  --red-bg: rgba(214, 69, 69, 0.14);
}
* { box-sizing: border-box; margin: 0; }
body {
  font-family: -apple-system, system-ui, Roboto, sans-serif;
  background: var(--bg2);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  padding-bottom: 64px;
}
#app { padding: 12px 12px 0; max-width: 560px; margin: 0 auto; }
.hidden { display: none; }
.loading, .empty { color: var(--hint); text-align: center; padding: 32px 8px; }

.card {
  background: var(--bg);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.header-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px; padding: 0 2px;
}
.header-date { font-size: 14px; color: var(--hint); text-transform: capitalize; }
.badge {
  font-size: 12px; padding: 2px 10px; border-radius: 99px;
  background: var(--bg); color: var(--hint);
}
.badge.stale { background: var(--orange-bg); color: var(--orange); }

.banner { border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; }
.banner .label { font-weight: 600; font-size: 16px; }
.banner .sub { font-size: 13px; margin-top: 2px; opacity: 0.9; }
.banner.green { background: var(--green-bg); color: var(--green); }
.banner.blue { background: var(--blue-bg); color: var(--blue); }
.banner.orange { background: var(--orange-bg); color: var(--orange); }
.banner.red { background: var(--red-bg); color: var(--red); }
.banner .why { font-size: 13px; text-decoration: underline; cursor: pointer; margin-top: 4px; display: inline-block; }
.reason-full { font-size: 13px; margin-top: 8px; white-space: pre-wrap; color: var(--text); }

.context-banner {
  border: 1px solid var(--orange); border-radius: 12px;
  padding: 8px 12px; margin-bottom: 10px; font-size: 13px; color: var(--orange);
  background: var(--bg);
}

.workout .overline { font-size: 12px; color: var(--hint); text-transform: uppercase; letter-spacing: 0.4px; }
.workout .title { font-size: 17px; font-weight: 600; margin-top: 2px; }
.workout .meta { font-size: 13px; color: var(--hint); margin-top: 2px; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.tile { background: var(--bg); border-radius: 12px; padding: 8px 6px 8px 10px; }
.tile .k { font-size: 11px; color: var(--hint); }
.tile .v { font-size: 16px; font-weight: 600; margin-top: 1px; }
.tile .sub { font-size: 10px; color: var(--hint); }
.tone-good .v, .tone-accent .v { color: var(--green); }
.tone-warn .v { color: var(--orange); }
.tone-bad .v { color: var(--red); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  font-size: 12px; padding: 3px 10px; border-radius: 99px;
  background: var(--bg); color: var(--hint); border: 1px solid rgba(128,128,128,0.25);
}

.section-title { font-size: 13px; font-weight: 600; color: var(--hint); margin: 12px 2px 6px; text-transform: uppercase; letter-spacing: 0.4px; }

.week-strip { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 6px; }
.week-day {
  min-width: 96px; background: var(--bg); border-radius: 12px; padding: 8px 10px;
  font-size: 12px; flex-shrink: 0;
}
.week-day .d { color: var(--hint); font-size: 11px; }
.week-day .t { font-weight: 600; margin-top: 2px; }

.watch-item { display: flex; gap: 8px; padding: 6px 0; font-size: 13px; }
.watch-item .wbadge { flex-shrink: 0; width: 20px; text-align: center; font-weight: 600; }
.watch-item .head { font-weight: 600; }
.watch-item .body { color: var(--hint); }

.period-switch { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.period-switch button {
  border: 1px solid rgba(128,128,128,0.3); background: var(--bg); color: var(--text);
  border-radius: 9px; padding: 4px 14px; font-size: 13px; cursor: pointer;
}
.period-switch button.active { background: var(--link); color: #fff; border-color: var(--link); }
.period-label { font-size: 13px; color: var(--hint); }

.decision-strip { display: flex; gap: 3px; margin-bottom: 12px; }
.decision-chip { flex: 1; height: 22px; border-radius: 4px; background: var(--bg); min-width: 4px; }
.dec-GREEN { background: var(--green); }
.dec-YELLOW { background: var(--blue); }
.dec-AMBER { background: var(--orange); }
.dec-RED, .dec-MEDICAL, .dec-AMS_FLAG { background: var(--red); }
.dec-none { background: rgba(128,128,128,0.2); }

.spark-block { margin-bottom: 10px; }
.spark-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 2px; }
.spark-head .name { font-weight: 600; }
.spark-head .cur { color: var(--hint); }
.spark-block svg { width: 100%; height: 44px; display: block; background: var(--bg); border-radius: 8px; }

.journal-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  padding: 7px 0; border-bottom: 1px solid rgba(128,128,128,0.15); font-size: 13px;
}
.journal-row:last-child { border-bottom: none; }
.journal-row .jdate { color: var(--hint); white-space: nowrap; }
.journal-row .jtitle { flex: 1; }
.journal-row .jout { color: var(--hint); text-align: right; white-space: nowrap; }
.journal-row .jout.bad { color: var(--red); }
.jdec { font-size: 11px; padding: 1px 8px; border-radius: 99px; font-weight: 600; }
.jdec.dec-GREEN { background: var(--green-bg); color: var(--green); }
.jdec.dec-YELLOW { background: var(--blue-bg); color: var(--blue); }
.jdec.dec-AMBER { background: var(--orange-bg); color: var(--orange); }
.jdec.dec-RED, .jdec.dec-MEDICAL, .jdec.dec-AMS_FLAG { background: var(--red-bg); color: var(--red); }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex;
  background: var(--bg); border-top: 1px solid rgba(128,128,128,0.2);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; border: none; background: none; color: var(--hint);
  font-size: 14px; padding: 12px 0; cursor: pointer;
}
.tabbar button.active { color: var(--link); font-weight: 600; }

.form-title { font-size: 16px; font-weight: 600; }
.form-hint { font-size: 12px; color: var(--hint); margin: 4px 0 10px; }
.field-label { font-size: 13px; color: var(--hint); margin: 10px 0 4px; }
.scale { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.scale-3 { grid-template-columns: repeat(3, 1fr); }
.scale-6 { grid-template-columns: repeat(6, 1fr); }
.scale-10 { grid-template-columns: repeat(10, 1fr); }
.scale-6 button, .scale-10 button { padding: 8px 0; }
.note-input {
  width: 100%; border: 1px solid rgba(128,128,128,0.3); background: var(--bg);
  color: var(--text); border-radius: 9px; padding: 9px 10px; font-size: 14px;
}
.note-input::placeholder { color: var(--hint); }
.subform.hidden { display: none; }
.scale button {
  border: 1px solid rgba(128,128,128,0.3); background: var(--bg); color: var(--text);
  border-radius: 9px; padding: 8px 2px; font-size: 12px; cursor: pointer;
}
.scale button.selected { background: var(--link); color: #fff; border-color: var(--link); }
.submit-btn {
  width: 100%; margin-top: 14px; border: none; border-radius: 10px;
  background: var(--link); color: #fff; font-size: 15px; font-weight: 600;
  padding: 11px 0; cursor: pointer;
}
.submit-btn:disabled { opacity: 0.45; cursor: default; }
.checkin-done { text-align: center; padding: 28px 10px; }
.checkin-done .big { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.checkin-done .note { font-size: 13px; color: var(--hint); }

.error-box { text-align: center; padding: 24px 8px; color: var(--hint); }
.error-box button {
  margin-top: 10px; border: 1px solid var(--link); color: var(--link);
  background: none; border-radius: 9px; padding: 6px 18px; font-size: 14px; cursor: pointer;
}
