/* main.css — styles ที่ Tailwind CDN ทำไม่ได้ */

/* ── CSS Variables ─────────────────────────────────────── */
:root {
  --blue:        #1A56E8;
  --blue-light:  #E8F0FE;
  --blue-mid:    #4B7FFF;
  --green:       #12C76A;
  --green-light: #E6FAF0;
  --orange:      #FF8C00;
  --orange-light:#FFF4E0;
  --red:         #E84040;
  --red-light:   #FEE8E8;
  --bg:          #F4F7FF;
  --border:      #D6E0FF;
  --text:        #0D1B3E;
  --text-muted:  #6B7A9C;
  --white:       #FFFFFF;
}

/* ── Loader spinner ─────────────────────────────────────── */
.loader-ring {
  width: 52px; height: 52px;
  border: 5px solid var(--blue-light);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Tab content show/hide ──────────────────────────────── */
.tab-content        { display: none; }
.tab-content.active { display: block; }

.tab-btn.active {
  color: var(--blue) !important;
  border-bottom-color: var(--blue) !important;
}

/* ── Onboarding page show/hide ──────────────────────────── */
.ob-page        { display: none; }
.ob-page.active { display: flex; }

.ob-step.active { background: rgba(255,255,255,0.6); }
.ob-step.done   { background: white; }

/* ── OVERLAY — ม่านดำหลัง sheet ────────────────────────── */
.sheet-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(13, 27, 62, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.sheet-overlay.active { display: block; }

/* ── Sheet slide-up animation ───────────────────────────── */
.sheet {
  /* ยึดกับ viewport แต่ clamp ไม่เกิน 480px และ center เหมือน body */
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  width: 100%;
  max-width: 480px;
  background: white;
  border-radius: 24px 24px 0 0;
  z-index: 101;
  max-height: 85dvh;
  overflow-y: auto;
  transition: transform 0.3s cubic-bezier(.22, 1, .36, 1);
  /* safe area */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet.slide-up {
  transform: translateX(-50%) translateY(0);
}

/* ── Progress bar transition + color variants ───────────── */
.progress-fill {
  transition: width 0.6s cubic-bezier(.22, 1, .36, 1);
}
.progress-fill.good { background: var(--blue-mid) !important; }
.progress-fill.done { background: var(--green) !important; }

/* ── Toggle button selected states (set by JS) ──────────── */
.toggle-btn.selected,
.gender-btn.selected,
.time-btn.selected    {
  border-color: var(--blue) !important;
  background: var(--blue-light) !important;
  color: var(--blue) !important;
}
.day-toggle.selected  {
  border-color: var(--blue) !important;
  background: var(--blue) !important;
  color: white !important;
}
.goal-btn.selected {
  border-color: var(--blue) !important;
  background: var(--blue-light) !important;
}
.meal-pattern-btn.selected {
  border-color: var(--blue) !important;
  background: var(--blue) !important;
  color: white !important;
}
.food-cat-btn.selected {
  border-color: var(--blue) !important;
  background: var(--blue) !important;
}
.food-cat-btn.selected .fc-label { color: white; }

/* ── JS-generated Meal Cards ────────────────────────────── */
.plan-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.plan-title { font-size: 16px; font-weight: 800; color: var(--text); }
.plan-total {
  font-size: 15px; font-weight: 700; color: var(--blue);
  background: var(--blue-light); padding: 3px 12px; border-radius: 99px;
}
.plan-total.reached { background: var(--green-light); color: var(--green); }

.meal-card {
  background: white; border-radius: 16px;
  border: 2px solid var(--border); padding: 16px;
  margin-bottom: 10px;
  box-shadow: 0 2px 12px rgba(26,86,232,0.10);
  animation: fadeIn 0.25s ease both;
}
.meal-card.logged { border-color: var(--green); background: var(--green-light); }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.meal-card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.meal-slot-badge {
  font-size: 12px; font-weight: 700; color: var(--blue);
  background: var(--blue-light); padding: 3px 10px; border-radius: 99px;
}
.logged-badge { font-size: 12px; font-weight: 700; color: var(--green); }
.meal-card-body { margin-bottom: 12px; }
.meal-name     { font-size: 18px; font-weight: 800; color: var(--text); margin-bottom: 4px; line-height: 1.3; }
.meal-protein  { font-size: 28px; font-weight: 800; color: var(--blue); line-height: 1; margin-bottom: 6px; }
.meal-addons   { font-size: 13px; font-weight: 600; color: var(--blue-mid); margin-bottom: 6px; }
.meal-instruction {
  font-size: 13px; font-weight: 500; color: var(--text-muted);
  background: var(--bg); border-radius: 6px; padding: 6px 10px;
  margin-bottom: 6px; line-height: 1.5;
}
.cat-badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  color: var(--text-muted); background: var(--bg);
  border-radius: 99px; padding: 2px 8px; margin-right: 4px;
}
.warn-badges { font-size: 12px; font-weight: 600; color: var(--orange); margin-top: 4px; }

.meal-card-actions { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }

.btn-eat {
  height: 44px; background: var(--blue); color: white;
  border: none; border-radius: 10px;
  font-family: 'Kanit', sans-serif; font-size: 14px; font-weight: 700;
  cursor: pointer; transition: transform 0.15s;
}
.btn-eat:active { transform: scale(0.96); }
.btn-swap {
  height: 44px; background: white; color: var(--text-muted);
  border: 2px solid var(--border); border-radius: 10px;
  font-family: 'Kanit', sans-serif; font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.btn-swap:active { background: var(--bg); }
.btn-addon {
  height: 44px; background: var(--orange-light); color: var(--orange);
  border: 2px solid var(--orange); border-radius: 10px;
  font-family: 'Kanit', sans-serif; font-size: 13px; font-weight: 700;
  cursor: pointer;
}
.btn-undo {
  height: 40px; width: 100%; background: transparent;
  color: var(--text-muted); border: 1.5px solid var(--border);
  border-radius: 10px; font-family: 'Kanit', sans-serif;
  font-size: 13px; font-weight: 600; cursor: pointer;
}

/* ── Bar chart (JS-generated) ───────────────────────────── */
.bar-col {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; gap: 4px; height: 100%;
}
.bar-value  { font-size: 10px; font-weight: 700; color: var(--text-muted); min-height: 14px; text-align: center; }
.bar-wrap   { flex: 1; width: 100%; position: relative; display: flex; align-items: flex-end; }
.bar-fill   {
  width: 100%; border-radius: 6px 6px 0 0;
  background: var(--blue-mid); min-height: 4px;
  transition: height 0.6s cubic-bezier(.22, 1, .36, 1);
}
.bar-fill.reached   { background: var(--green); }
.bar-target-line    { position: absolute; left: 0; right: 0; height: 2px; background: var(--red); opacity: 0.5; }
.bar-label          { font-size: 11px; font-weight: 700; color: var(--text-muted); }
.bar-col.today .bar-fill  { background: var(--blue); }
.bar-col.today .bar-label { color: var(--blue); font-weight: 800; }

/* ── Add-on buttons (JS-generated) ─────────────────────── */
.addon-btn {
  width: 100%; height: 60px;
  border: 2px solid var(--border); border-radius: 16px;
  background: white; font-family: 'Kanit', sans-serif;
  cursor: pointer; display: flex; align-items: center;
  justify-content: space-between; padding: 0 18px;
  margin-bottom: 10px; transition: all 0.15s;
}
.addon-name { font-size: 15px; font-weight: 700; color: var(--text); }
.addon-prot {
  font-size: 15px; font-weight: 800; color: var(--blue);
  background: var(--blue-light); padding: 4px 12px; border-radius: 99px;
}
.addon-btn.selected { border-color: var(--blue); background: var(--blue-light); }
.addon-btn.selected .addon-prot { background: var(--blue); color: white; }

/* ── Toast show state ───────────────────────────────────── */
#toast.show { opacity: 1 !important; }

/* ── Error message (onboarding) ─────────────────────────── */
.error-msg         { display: none; }
.error-msg.show    { display: block; }
