:root {
  --bg:        #f2f2f7;
  --bg-2:      #ffffff;
  --bg-3:      #f2f2f7;
  --border:    rgba(0,0,0,0.10);
  --blue:      #007aff;
  --blue-dim:  rgba(0,122,255,0.10);
  --green:     #30d158;
  --green-dim: rgba(48,209,88,0.12);
  --red:       #ff3b30;
  --red-dim:   rgba(255,59,48,0.10);
  --text:      #1d1d1f;
  --text-2:    #6e6e73;
  --text-3:    #aeaeb2;
  --white:     #ffffff;
  --shadow:    0 4px 24px rgba(0,0,0,0.07), 0 1px 4px rgba(0,0,0,0.04);
  --shadow-sm: 0 1px 8px rgba(0,0,0,0.06);
  --glass:     rgba(255,255,255,0.76);
  --font:      -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', Arial, sans-serif;
  --mono:      'SF Mono', ui-monospace, 'Fira Code', monospace;

  /* Backwards-compat aliases for inline styles in HTML pages */
  --sans:       var(--font);
  --bg-2:       var(--white);
  --bg-3:       var(--bg);
  --gray:       var(--text-2);
  --gray-light: var(--text-3);
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

/* ── NAV ─────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%; max-width: 480px;
  background: var(--glass);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-top: 0.5px solid rgba(0,0,0,0.12);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 0 8px;
  text-decoration: none;
  color: var(--text-3);
  font-family: var(--font);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: color 0.15s;
}

.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--blue); }
.nav-item:hover { color: var(--text-2); }

/* ── LAYOUT ──────────────────────────────────────────────────── */
.page {
  padding: 20px 16px 110px;
  min-height: 100vh;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-top: env(safe-area-inset-top);
}

.page-title {
  font-family: var(--font);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--text);
}

.date-label {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.02em;
}

/* ── CARDS ───────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: 20px;
  padding: 18px 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.card-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.01em;
  margin-bottom: 10px;
  text-transform: none;
}

.card-value {
  font-size: 36px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1;
}

.card-value span {
  font-size: 16px;
  color: var(--text-3);
  font-weight: 400;
  margin-left: 4px;
}

/* ── PROGRESS BAR ────────────────────────────────────────────── */
.progress-wrap {
  margin-top: 10px;
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--blue);
  border-radius: 3px;
  transition: width 0.4s ease;
  min-width: 0;
}

.progress-bar.green { background: var(--green); }
.progress-bar.red   { background: var(--red); }

.progress-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-3);
}

/* ── DOTS ────────────────────────────────────────────────────── */
.dots { display: flex; gap: 8px; margin-top: 10px; }

.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--bg);
  border: 1.5px solid var(--text-3);
  transition: background 0.2s;
}

.dot.filled          { background: var(--green); border-color: var(--green); }
.dot.filled.red      { background: var(--red);   border-color: var(--red); }

/* ── STAT ROW ────────────────────────────────────────────────── */
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── QUICK ACTIONS ───────────────────────────────────────────── */
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }

/* ── BUTTONS ─────────────────────────────────────────────────── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 15px 20px;
  border-radius: 14px;
  border: none;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.btn:active { transform: scale(0.97); opacity: 0.85; }

.btn-primary {
  background: var(--blue);
  color: #fff;
}

.btn-primary:active { background: #0066d6; }

.btn svg { width: 16px; height: 16px; }

/* ── PHOTO BUTTON ────────────────────────────────────────────── */
.photo-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 15px;
  border-radius: 14px;
  border: 1.5px dashed var(--text-3);
  background: var(--bg);
  color: var(--text-2);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  width: 100%;
  margin-bottom: 10px;
}

.photo-btn:active { opacity: 0.7; transform: scale(0.97); }
.photo-btn.has-image { border-style: solid; border-color: var(--blue); color: var(--blue); }

/* ── FORMS ───────────────────────────────────────────────────── */
.input-wrap { position: relative; margin-bottom: 12px; }

.input-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 8px;
}

input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  background: var(--bg);
  border: none;
  border-radius: 12px;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  padding: 14px 16px;
  outline: none;
  transition: box-shadow 0.15s;
  -webkit-appearance: none;
}

input:focus, textarea:focus, select:focus {
  box-shadow: 0 0 0 3px var(--blue-dim);
}

textarea { resize: none; min-height: 80px; }

/* ── DURATION CHIPS ──────────────────────────────────────────── */
.duration-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

.duration-btn {
  padding: 8px 16px;
  border-radius: 20px;
  border: none;
  background: var(--bg);
  color: var(--text-2);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.duration-btn:hover,
.duration-btn.active {
  background: var(--blue);
  color: #fff;
}

/* ── MACRO RESULT ────────────────────────────────────────────── */
.macro-result {
  background: var(--white);
  border-radius: 20px;
  padding: 18px 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  display: none;
}

.macro-result.visible { display: block; }

.macro-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.macro-item { text-align: center; }

.macro-num {
  font-size: 20px;
  font-weight: 700;
  color: var(--blue);
  display: block;
  letter-spacing: -0.02em;
}

.macro-lbl {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── MEAL LIST ───────────────────────────────────────────────── */
.meal-list { margin-top: 20px; }

.meal-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 0;
  border-bottom: 0.5px solid var(--border);
}

.meal-item:last-child { border-bottom: none; }

.meal-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
  margin-right: 12px;
}

.meal-macros {
  font-size: 13px;
  color: var(--text-2);
  text-align: right;
  flex-shrink: 0;
}

.meal-macros strong { color: var(--blue); font-weight: 600; }

/* ── SECTION TITLE ───────────────────────────────────────────── */
.section-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 12px;
  margin-top: 28px;
}

/* ── CHART ───────────────────────────────────────────────────── */
canvas { width: 100% !important; border-radius: 12px; }

/* ── WORKOUT ITEMS ───────────────────────────────────────────── */
.workout-item { padding: 14px 0; border-bottom: 0.5px solid var(--border); }
.workout-item:last-child { border-bottom: none; }
.workout-title { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.workout-meta { font-size: 13px; color: var(--text-2); }

/* ── WEIGHT STATS ────────────────────────────────────────────── */
.weight-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.weight-stat {
  background: var(--white);
  border-radius: 16px;
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.weight-stat-num {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  display: block;
  letter-spacing: -0.02em;
}

.weight-stat-lbl {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 4px;
  display: block;
}

/* ── LOADING SPINNER ─────────────────────────────────────────── */
.loading {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── TOAST ───────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: rgba(40,40,40,0.92);
  backdrop-filter: blur(12px);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 20px;
  opacity: 0;
  transition: all 0.22s cubic-bezier(.34,1.56,.64,1);
  pointer-events: none;
  white-space: nowrap;
  z-index: 200;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── EMPTY STATE ─────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-3);
  font-size: 15px;
}

/* ── DELETE BTN ──────────────────────────────────────────────── */
.delete-btn {
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  padding: 4px 8px;
  font-size: 18px;
  border-radius: 8px;
  transition: all 0.15s;
}

.delete-btn:hover { color: var(--red); background: var(--red-dim); }

/* ── SCROLLBAR ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 0; }

/* ── PHOTO PREVIEW ───────────────────────────────────────────── */
.photo-preview {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: 14px;
  margin-bottom: 10px;
  display: none;
}
.photo-preview.visible { display: block; }
