/* ============================================================
   Nabcal — app.css (hand-crafted starter, mobile-first)
   ============================================================
   ไฟล์นี้เป็น standalone CSS ใช้งานได้ทันทีไม่ต้องรัน build
   ถ้าต้องการ Tailwind utilities เต็มรูปแบบ ให้รัน
     npm install && npm run build:css
   เพื่อสร้าง app.css ใหม่ทับ (จะมี utility classes ครบ)
   ============================================================ */

/* ========== 1) Reset / base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  font-family: 'Noto Sans Thai', 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-bg);
  min-height: 100vh;
  min-height: 100dvh;
  /* iOS safe area */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
img, svg { display: block; max-width: 100%; }
button { font: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font: inherit; }
a { color: inherit; text-decoration: none; }

/* ========== 2) Theme tokens ========== */
:root {
  /* Brand: ส้มอบอุ่น (food/health vibe) */
  --c-brand-50:  #fff7ed;
  --c-brand-100: #ffedd5;
  --c-brand-400: #fb923c;
  --c-brand-500: #f97316;
  --c-brand-600: #ea580c;
  --c-brand-700: #c2410c;

  --c-text:        #1f2937;
  --c-text-muted:  #6b7280;
  --c-bg:          #f9fafb;
  --c-card:        #ffffff;
  --c-border:      #e5e7eb;
  --c-border-strong: #d1d5db;

  --c-success: #16a34a;
  --c-warn:    #d97706;
  --c-danger:  #dc2626;
  --c-info:    #2563eb;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.12);

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

/* ========== 3) Layout helpers ========== */
.container {
  width: 100%;
  max-width: 480px;
  margin-inline: auto;
  padding-inline: 16px;
}
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.grid { display: grid; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }

.text-center { text-align: center; }
.text-right  { text-align: right; }
.w-full { width: 100%; }
.hidden { display: none !important; }

.mt-1{margin-top:4px} .mt-2{margin-top:8px} .mt-3{margin-top:12px} .mt-4{margin-top:16px} .mt-6{margin-top:24px} .mt-8{margin-top:32px}
.mb-1{margin-bottom:4px} .mb-2{margin-bottom:8px} .mb-3{margin-bottom:12px} .mb-4{margin-bottom:16px} .mb-6{margin-bottom:24px} .mb-8{margin-bottom:32px}
.p-2{padding:8px} .p-3{padding:12px} .p-4{padding:16px} .p-6{padding:24px}
.px-2{padding-inline:8px} .px-3{padding-inline:12px} .px-4{padding-inline:16px}
.py-2{padding-block:8px} .py-3{padding-block:12px} .py-4{padding-block:16px}

/* ========== 4) Typography ========== */
.text-xs { font-size: 12px; }
.text-sm { font-size: 14px; }
.text-base { font-size: 16px; }
.text-lg { font-size: 18px; }
.text-xl { font-size: 20px; line-height: 1.3; }
.text-2xl { font-size: 24px; line-height: 1.25; }
.text-3xl { font-size: 30px; line-height: 1.2; }
.text-4xl { font-size: 36px; line-height: 1.1; }

.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.text-muted { color: var(--c-text-muted); }
.text-brand { color: var(--c-brand-600); }
.text-success { color: var(--c-success); }
.text-warn { color: var(--c-warn); }
.text-danger { color: var(--c-danger); }

/* ========== 5) Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background 0.15s, transform 0.05s, opacity 0.15s;
  user-select: none;
  -webkit-user-select: none;
  min-height: 44px; /* iOS touch target */
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--c-brand-500);
  color: white;
}
.btn-primary:hover { background: var(--c-brand-600); }
.btn-secondary {
  background: var(--c-card);
  color: var(--c-text);
  border-color: var(--c-border-strong);
}
.btn-secondary:hover { background: var(--c-bg); }
.btn-ghost {
  background: transparent;
  color: var(--c-brand-600);
}
.btn-ghost:hover { background: var(--c-brand-50); }
.btn-danger {
  background: var(--c-danger);
  color: white;
}
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 14px; min-height: 36px; }
.btn-lg { padding: 14px 20px; font-size: 18px; min-height: 52px; }

/* ========== 6) Forms ========== */
.form-group { display: block; margin-bottom: 16px; }
.label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--c-text);
  margin-bottom: 6px;
}
.label-required::after { content: ' *'; color: var(--c-danger); }
.input, .select, .textarea {
  display: block;
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  color: var(--c-text);
  background: var(--c-card);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--c-brand-500);
  box-shadow: 0 0 0 3px var(--c-brand-100);
}
.input:disabled, .select:disabled { background: var(--c-bg); cursor: not-allowed; }
.input.error, .select.error { border-color: var(--c-danger); }
.field-help { font-size: 13px; color: var(--c-text-muted); margin-top: 4px; }
.field-error { font-size: 13px; color: var(--c-danger); margin-top: 4px; }

/* radio/checkbox group */
.radio-group { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-card {
  flex: 1 1 calc(50% - 4px);
  min-width: 130px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border: 1.5px solid var(--c-border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--c-card);
  transition: all 0.15s;
}
.radio-card:hover { border-color: var(--c-brand-400); }
.radio-card input { display: none; }
.radio-card.selected,
.radio-card:has(input:checked) {
  border-color: var(--c-brand-500);
  background: var(--c-brand-50);
}
.radio-card-title { font-weight: 600; font-size: 14px; }
.radio-card-desc { font-size: 12px; color: var(--c-text-muted); }

/* ========== 7) Card ========== */
.card {
  background: var(--c-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--c-border);
}
.card-title { font-size: 18px; font-weight: 700; margin-bottom: 12px; }

/* ========== 8) Header / Nav ========== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--c-card);
  border-bottom: 1px solid var(--c-border);
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.app-header-title { font-size: 18px; font-weight: 700; }

/* ========== 9) Progress bar (สำหรับ macros) ========== */
.progress {
  width: 100%;
  height: 8px;
  background: var(--c-border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--c-brand-500);
  border-radius: inherit;
  transition: width 0.3s ease-out;
}
.progress-bar.over { background: var(--c-danger); }
.progress-bar.protein { background: #2563eb; }
.progress-bar.carb    { background: #16a34a; }
.progress-bar.fat     { background: #d97706; }

/* ========== 10) Alerts / Toast ========== */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 14px;
}
.alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-warn    { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-danger  { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

/* ========== 11) Auth screen ========== */
.auth-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 20px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}
.auth-logo {
  font-size: 32px;
  font-weight: 800;
  color: var(--c-brand-600);
  text-align: center;
  margin-bottom: 8px;
}
.auth-tagline {
  text-align: center;
  color: var(--c-text-muted);
  margin-bottom: 32px;
}

/* ========== 12) Loading spinner ========== */
.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.loading-card {
  background: white;
  padding: 24px 32px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 500;
}

/* ========== 13) Bottom nav (Phase 2+) ========== */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--c-card);
  border-top: 1px solid var(--c-border);
  padding: 8px 16px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-around;
  z-index: 5;
}
.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  font-size: 11px;
  color: var(--c-text-muted);
  cursor: pointer;
}
.bottom-nav-item.active { color: var(--c-brand-600); }

/* ========== 14) FAB ========== */
.fab {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom));
  right: 16px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--c-brand-500);
  color: white;
  font-size: 28px;
  font-weight: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  z-index: 6;
}
.fab:active { transform: scale(0.95); }

/* ========== 15) Utility ========== */
.divider { height: 1px; background: var(--c-border); margin: 16px 0; }
.skeleton {
  background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
  background-size: 200% 100%;
  animation: skeleton 1.2s infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* Alpine x-cloak — ซ่อน element จนกว่า Alpine boot เสร็จ */
[x-cloak] { display: none !important; }

/* ========== 16) Onboarding stepper ========== */
.stepper {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
}
.stepper-dot {
  flex: 1;
  height: 4px;
  background: var(--c-border);
  border-radius: 999px;
}
.stepper-dot.active { background: var(--c-brand-500); }
.stepper-dot.done   { background: var(--c-brand-300, #fdba74); }

/* ========== 17) Sheet (modal slide-up) ========== */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 30;
  display: flex; flex-direction: column; justify-content: flex-end;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fade-in 0.15s ease-out;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  background: var(--c-card);
  border-top-left-radius: var(--radius-xl);
  border-top-right-radius: var(--radius-xl);
  max-height: 92dvh;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  animation: slide-up 0.2s ease-out;
  -webkit-overflow-scrolling: touch;
}
@keyframes slide-up {
  from { transform: translateY(20%); opacity: 0; }
  to   { transform: translateY(0);  opacity: 1; }
}
.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  position: sticky; top: -16px; background: var(--c-card);
  padding-top: 8px; padding-bottom: 8px;
  border-bottom: 1px solid var(--c-border);
  margin-left: -16px; margin-right: -16px;
  padding-left: 16px; padding-right: 16px;
}
.sheet-handle {
  width: 36px; height: 4px;
  background: var(--c-border-strong);
  border-radius: 999px;
  margin: 0 auto 12px;
}

/* sheet tabs */
.sheet-tabs {
  display: flex;
  gap: 4px;
  background: var(--c-bg);
  padding: 4px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.sheet-tab {
  flex: 1;
  padding: 10px 8px;
  border-radius: 8px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  color: var(--c-text-muted);
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: transparent;
}
.sheet-tab.active {
  background: var(--c-card);
  color: var(--c-text);
  box-shadow: var(--shadow-sm);
}

/* photo preview area */
.photo-dropzone {
  display: block;
  width: 100%;
  border: 2px dashed var(--c-border-strong);
  border-radius: var(--radius-lg);
  padding: 24px 16px;
  text-align: center;
  background: var(--c-bg);
  cursor: pointer;
  transition: all 0.15s;
  box-sizing: border-box;
}
.photo-dropzone:hover { border-color: var(--c-brand-400); }
.photo-dropzone-sm {
  padding: 14px 12px;
  font-size: 14px;
}

/* meal selector (4 across, compact) */
.meal-selector {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}
.meal-selector .meal-chip {
  padding: 8px 4px;
  border: 1.5px solid var(--c-border-strong);
  border-radius: var(--radius);
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: var(--c-card);
  transition: all 0.12s;
  user-select: none;
  -webkit-user-select: none;
}
.meal-selector .meal-chip input { display: none; }
.meal-selector .meal-chip.selected,
.meal-selector .meal-chip:has(input:checked) {
  background: var(--c-brand-50);
  border-color: var(--c-brand-500);
  color: var(--c-brand-700);
}

/* photo section — แต่ละรูปมี header + items grouped */
.photo-section {
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.photo-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--c-bg);
  border-bottom: 1px solid var(--c-border);
}
.photo-section-thumb {
  width: 56px; height: 56px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.photo-section-info {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--c-text-muted);
}
.photo-section-body {
  padding: 8px;
}
.photo-section-body .item-edit {
  margin-bottom: 6px;
  border: 1px solid var(--c-border);
}
.photo-section-body .item-edit:last-child { margin-bottom: 0; }
.photo-preview-wrap {
  position: relative;
  width: 100%; max-height: 360px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--c-bg);
}
.photo-preview-wrap img {
  width: 100%; height: 100%; object-fit: cover;
  max-height: 360px;
}

/* food item edit card (in review) */
.item-edit {
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
}
.item-edit.confidence-low {
  border-color: #fbbf24;
  background: #fffbeb;
}
.item-edit-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; margin-bottom: 8px;
}
.input-sm {
  padding: 8px 10px;
  font-size: 14px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius-sm);
  width: 100%;
  background: var(--c-card);
}
.input-sm:focus {
  outline: none;
  border-color: var(--c-brand-500);
  box-shadow: 0 0 0 2px var(--c-brand-100);
}
.input-icon-btn {
  background: transparent;
  border: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  color: var(--c-danger);
  display: flex; align-items: center; justify-content: center;
}
.input-icon-btn:hover { background: var(--c-bg); }

/* food log entry on dashboard */
.log-entry {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  margin-bottom: 6px;
}
.log-entry-thumb {
  width: 48px; height: 48px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--c-bg);
  flex-shrink: 0;
}
.log-entry-thumb-empty {
  width: 48px; height: 48px;
  background: var(--c-bg);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--c-text-muted);
  font-size: 20px;
  flex-shrink: 0;
}
.log-entry-body {
  flex: 1; min-width: 0;
}
.log-entry-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.log-entry-meta {
  font-size: 12px;
  color: var(--c-text-muted);
  margin-top: 2px;
}
.log-entry-cal {
  font-weight: 700;
  font-size: 16px;
  color: var(--c-text);
}

/* meal section */
.meal-section { margin-bottom: 16px; }
.meal-section-header {
  display: flex; justify-content: space-between; align-items: baseline;
  font-weight: 600;
  font-size: 14px;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  padding: 0 4px;
}

/* date nav */
.date-nav {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 16px;
}
.date-nav-arrow {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none; background: transparent;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  color: var(--c-text);
  cursor: pointer;
}
.date-nav-arrow:hover { background: var(--c-bg); }
.date-nav-arrow:disabled { opacity: 0.3; cursor: not-allowed; }
.date-nav-label {
  font-weight: 600;
  font-size: 16px;
}

/* progress card */
.macro-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
}
.macro-label {
  width: 70px;
  font-size: 13px;
  color: var(--c-text-muted);
  flex-shrink: 0;
}
.macro-bar { flex: 1; }
.macro-value {
  font-size: 13px;
  color: var(--c-text);
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  text-align: right;
  min-width: 90px;
}

/* recent food card */
.recent-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-card);
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 6px;
  width: 100%;
  text-align: left;
}
.recent-card:hover {
  border-color: var(--c-brand-400);
  background: var(--c-brand-50);
}
.recent-card:active { transform: scale(0.98); }

/* ========== 18) Responsive ========== */
@media (min-width: 640px) {
  .container { max-width: 540px; }
  .sheet-backdrop { justify-content: center; align-items: center; }
  .sheet { max-width: 500px; max-height: 90vh; border-radius: var(--radius-xl); }
}
