:root {
  --forest-900: #16301f;
  --forest-800: #1f4229;
  --forest-700: #2d5a3d;
  --forest-600: #3a7350;
  --forest-100: #e3efe6;
  --gold: #d4af37;
  --gold-dark: #a8842a;
  --orange: #e07a2f;
  --orange-dark: #c15f1c;
  --bg: #f6f4ec;
  --card-bg: #ffffff;
  --text: #21281f;
  --text-muted: #5c6b5e;
  --danger: #c0392b;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(22, 48, 31, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Sarabun", "Kanit", sans-serif;
  font-size: 18px;
  line-height: 1.5;
  padding-bottom: 96px;
}

h1, h2, h3, .brand-name, button, select {
  font-family: "Kanit", "Sarabun", sans-serif;
}

.hidden { display: none !important; }

.topbar {
  background: linear-gradient(135deg, var(--forest-800), var(--forest-700));
  color: #fff;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 26px; }
.brand-name { font-size: 22px; font-weight: 700; letter-spacing: 0.3px; }

.app { max-width: 640px; margin: 0 auto; padding: 16px; }

.view { animation: fadeIn 0.15s ease-in; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.section-title {
  font-size: 20px;
  font-weight: 600;
  margin: 24px 0 12px;
  color: var(--forest-800);
}

/* Day navigation */
.day-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.day-label { font-size: 20px; font-weight: 600; color: var(--forest-800); }
.icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--forest-100);
  color: var(--forest-800);
  font-size: 24px;
  cursor: pointer;
}
.icon-btn:active { background: var(--forest-600); color: #fff; }

/* Mode toggle */
.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.mode-btn {
  padding: 16px 10px;
  border-radius: var(--radius);
  border: 2px solid var(--forest-100);
  background: #fff;
  font-size: 17px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.mode-btn.active[data-mode="workout"] {
  background: var(--orange);
  border-color: var(--orange-dark);
  color: #fff;
}
.mode-btn.active[data-mode="rest"] {
  background: var(--forest-700);
  border-color: var(--forest-800);
  color: #fff;
}

/* Progress */
.progress-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.progress-row + .progress-row { margin-top: 16px; }
.progress-label {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  margin-bottom: 6px;
}
.progress-value { color: var(--text-muted); font-weight: 500; font-size: 15px; }
.progress-track {
  height: 14px;
  background: var(--forest-100);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--gold);
  transition: width 0.3s ease;
}
.progress-fill.on-target { background: var(--forest-600); }
.progress-fill.over { background: var(--orange); }
.progress-sub { margin-top: 4px; font-size: 14px; color: var(--text-muted); }

/* Cards & forms */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
form label {
  display: block;
  font-weight: 600;
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
input, select {
  width: 100%;
  margin-top: 6px;
  padding: 14px;
  font-size: 17px;
  border: 2px solid var(--forest-100);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--forest-600); }

.macro-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
  margin-top: 8px;
}

.btn {
  display: inline-block;
  width: 100%;
  padding: 16px;
  border-radius: 12px;
  border: none;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
}
.btn-primary { background: var(--forest-700); color: #fff; }
.btn-primary:active { background: var(--forest-800); }
.btn-gold { background: var(--gold); color: var(--forest-900); }
.btn-gold:active { background: var(--gold-dark); }
.btn-outline {
  background: #fff;
  color: var(--forest-700);
  border: 2px solid var(--forest-100);
  width: auto;
  padding: 10px 16px;
}

.hint { font-size: 14px; color: var(--text-muted); margin: 6px 0; }
.error { color: var(--danger); font-size: 15px; }

.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute;
  z-index: 10;
  left: 0; right: 0;
  top: 100%;
  margin: 4px 0 0;
  padding: 6px;
  list-style: none;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(22, 48, 31, 0.18);
  max-height: 220px;
  overflow-y: auto;
}
.autocomplete-list li {
  padding: 12px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
}
.autocomplete-list li:active { background: var(--forest-100); }

/* Meal list */
.meal-list { display: flex; flex-direction: column; gap: 10px; }
.meal-item {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.meal-item .meal-info { flex: 1; }
.meal-item .meal-name { font-weight: 600; }
.meal-item .meal-meta { font-size: 14px; color: var(--text-muted); margin-top: 2px; }
.meal-item .meal-macros { font-size: 13px; color: var(--forest-700); margin-top: 4px; }
.meal-item .delete-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 22px;
  cursor: pointer;
  padding: 8px;
}
.empty-state { text-align: center; color: var(--text-muted); padding: 24px 0; }

/* Summary */
.summary-actions { display: flex; gap: 10px; margin-bottom: 12px; }
.date-checklist {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
}
.date-check-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 10px;
}
.date-check-item input { width: 22px; height: 22px; margin: 0; }
.date-check-item .dci-mode { margin-left: auto; font-size: 20px; }

.summary-result { margin-top: 20px; }
.summary-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}
.stat-box {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-box .stat-value { font-size: 26px; font-weight: 700; color: var(--forest-800); }
.stat-box .stat-label { font-size: 14px; color: var(--text-muted); }

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 200px;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px 10px 10px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}
.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  min-width: 28px;
  height: 100%;
}
.bar-col .bar {
  width: 100%;
  border-radius: 6px 6px 0 0;
  background: var(--forest-600);
}
.bar-col .bar.under { background: var(--gold); }
.bar-col .bar.over { background: var(--orange); }
.bar-col .bar-icon { font-size: 12px; margin-top: 4px; }
.bar-col .bar-date { font-size: 10px; color: var(--text-muted); margin-top: 2px; writing-mode: vertical-rl; }

/* Profile */
.targets-preview { margin-top: 16px; }
.targets-preview h4 { margin: 0 0 8px; color: var(--forest-800); }
.targets-preview table { width: 100%; border-collapse: collapse; font-size: 15px; }
.targets-preview td, .targets-preview th { padding: 8px 4px; text-align: center; border-bottom: 1px solid var(--forest-100); }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: #fff;
  box-shadow: 0 -2px 10px rgba(22, 48, 31, 0.12);
  padding: 6px 10px calc(env(safe-area-inset-bottom, 0px) + 6px);
  z-index: 20;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 0;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.nav-btn span { font-size: 22px; }
.nav-btn.active { color: var(--forest-700); }

/* Gate */
.gate {
  position: fixed;
  inset: 0;
  background: var(--forest-900);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.gate-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 28px 22px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}
.gate-card h2 { color: var(--forest-800); margin-top: 0; }
.gate-card p { color: var(--text-muted); font-size: 15px; }

@media (min-width: 480px) {
  body { font-size: 17px; }
}
