/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2d3250;
  --text: #e8eaf0;
  --muted: #7b82a0;
  --accent: #5b6af0;
  --accent-hover: #7380f7;
  --green: #34c97b;
  --red: #f04f5e;
  --yellow: #f5c542;
  --radius: 12px;
  --nav-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}

/* ── Bottom nav ────────────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 100;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.65rem;
  font-family: var(--font);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0;
  transition: color 0.15s;
}
.nav-btn svg { width: 22px; height: 22px; stroke-width: 1.8; }
.nav-btn.active { color: var(--accent); }
.nav-btn:active { opacity: 0.7; }

/* ── Views ─────────────────────────────────────────────────────────────────── */
.view { display: none; padding: 16px 16px 8px; max-width: 600px; margin: 0 auto; }
.view.active { display: block; }

h1.page-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
}

/* ── Form ───────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 5px;
}
.form-group input, .form-group textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1.1rem;
  padding: 13px 14px;
  font-family: var(--font);
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s;
}
.form-group input:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.form-group input.required { border-left: 3px solid var(--accent); }
.form-group textarea { resize: vertical; min-height: 70px; font-size: 0.95rem; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.section-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin: 20px 0 12px;
}

.btn-primary {
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:active { transform: scale(0.98); background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Toast ──────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom, 0px));
  left: 50%; transform: translateX(-50%);
  background: var(--green);
  color: #fff;
  padding: 10px 22px;
  border-radius: 100px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 200;
  white-space: nowrap;
}
.toast.error { background: var(--red); }
.toast.show { opacity: 1; }

/* ── KPI cards ──────────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.kpi-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.kpi-value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; margin: 4px 0; }
.kpi-diff { font-size: 0.8rem; }
.kpi-diff.up { color: var(--red); }
.kpi-diff.down { color: var(--green); }
.kpi-diff.neutral { color: var(--muted); }

/* weight up = bad (red), down = good (green)   */
/* fat up = bad, muscle up = good — handled in JS */

/* ── Range selector ─────────────────────────────────────────────────────────── */
.range-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
}
.range-btn {
  flex: 1;
  padding: 8px 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  font-family: var(--font);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}
.range-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Chart cards ────────────────────────────────────────────────────────────── */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.chart-card h3 { font-size: 0.85rem; color: var(--muted); margin-bottom: 12px; font-weight: 500; }
.chart-wrap { position: relative; height: 180px; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }

/* ── History table ──────────────────────────────────────────────────────────── */
.export-bar { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.btn-secondary {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--border); }

.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.history-date { font-size: 0.9rem; font-weight: 600; }
.history-actions { display: flex; gap: 8px; }
.btn-icon {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  padding: 5px 8px;
  font-size: 0.75rem;
  font-family: var(--font);
  transition: all 0.15s;
}
.btn-icon.danger:hover { background: var(--red); border-color: var(--red); color: #fff; }
.btn-icon.edit:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

.history-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.history-item { font-size: 0.8rem; }
.history-item span { display: block; color: var(--muted); font-size: 0.65rem; }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
  font-size: 0.95rem;
}

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 300;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  width: 100%;
  max-width: 600px;
  transform: translateY(100%);
  transition: transform 0.25s ease;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-backdrop.open .modal { transform: translateY(0); }
.modal h2 { font-size: 1.1rem; margin-bottom: 16px; }
.modal-footer { display: flex; gap: 10px; margin-top: 16px; }
.modal-footer button { flex: 1; }

/* ── Login page ─────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
}
.login-logo { font-size: 1.5rem; font-weight: 800; text-align: center; margin-bottom: 28px; color: var(--accent); }
.login-error {
  background: rgba(240, 79, 94, 0.15);
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.875rem;
}

@media (min-width: 500px) {
  .view { padding: 24px 20px 16px; }
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .chart-wrap { height: 220px; }
}
