:root {
  --paddy-900: #1c3018;
  --paddy-700: #31532a;
  --paddy-500: #47713d;
  --paddy-400: #5f9451;
  --paddy-100: #dfeada;
  --paddy-50: #f2f7f0;
  --turmeric-500: #d69412;
  --turmeric-400: #e8ac2e;
  --clay-600: #a2431f;
  --clay-500: #c1552e;
  --cream: #fbf6ec;
  --ink: #241f18;
  --ink-soft: #5c5548;
  --line: #e3ddce;
  --white: #ffffff;
  --danger: #b3261e;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: "Sarabun", -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

body {
  padding-bottom: 76px; /* space for bottom nav */
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

/* ---------- App header ---------- */
.app-header {
  background: var(--paddy-900);
  color: var(--white);
  padding: 18px 20px 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.app-header h1 { margin: 2px 0 0; font-size: 19px; font-weight: 700; }
.app-header .eyebrow { margin: 0; font-size: 12px; color: var(--paddy-100); opacity: .85; }
.app-header .sub { margin: 4px 0 0; font-size: 13px; color: var(--paddy-100); }
.app-header .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ---------- Sections ---------- */
.section { padding: 16px 20px; }
.section h2 { font-size: 16px; margin: 0 0 12px; color: var(--paddy-900); }

/* ---------- Cards / rows ---------- */
.shop-row, .card-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.shop-row .meta { flex: 1; min-width: 0; }
.shop-row .name { font-weight: 700; margin: 0; font-size: 15px; }
.shop-row .sub { margin: 2px 0 0; font-size: 13px; color: var(--ink-soft); }
.shop-row .badge {
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px;
  background: var(--paddy-50); color: var(--paddy-700); white-space: nowrap;
}
.shop-row .badge.closed { background: #f5e9e4; color: var(--clay-600); }
.shop-row .badge.pending { background: #fbeecb; color: var(--turmeric-500); }

.empty-state {
  text-align: center;
  color: var(--ink-soft);
  padding: 32px 16px;
  font-size: 14px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity .15s;
}
.btn:active { opacity: .8; }
.btn-primary { background: var(--paddy-700); color: var(--white); }
.btn-primary:disabled { background: var(--line); color: var(--ink-soft); cursor: not-allowed; }
.btn-outline { background: transparent; color: var(--paddy-700); border: 1.5px solid var(--paddy-700); }
.btn-danger { background: transparent; color: var(--clay-600); border: 1.5px solid var(--clay-600); }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
input, textarea, select {
  font-family: inherit;
  font-size: 15px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1.5px solid var(--line);
  background: var(--white);
  color: var(--ink);
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--paddy-500);
}
/* checkbox/radio ไม่ควรยืดเต็มความกว้างเหมือน input ทั่วไป — กันเผลอลืม style="width:auto" ทีละจุด */
input[type="checkbox"], input[type="radio"] {
  width: auto;
  padding: 0;
}

/* ---------- Toggle switch ---------- */
/* แทนที่ checkbox ดิบสำหรับค่า เปิด/ปิด (เปิดรับออเดอร์, พร้อมรับงาน, ขาย, ส่งเอง)
   checkbox ของแต่ละเบราว์เซอร์/มือถือ render ขนาดไม่เท่ากันเอง ทำให้ชนกับข้อความข้างเคียงได้
   switch นี้ล็อกขนาดคงที่ 42x24px เอง ไม่พึ่งการ render ของเบราว์เซอร์ กันปัญหาแบบนี้ซ้ำ */
.switch {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  width: 42px;
  height: 24px;
  cursor: pointer;
}
.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.switch .track {
  position: absolute;
  inset: 0;
  background: rgba(36, 31, 24, .18);
  border-radius: 999px;
  transition: background .15s;
  pointer-events: none;
}
.switch .thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--white);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .15s;
}
.switch input:checked ~ .track { background: var(--paddy-500); }
.switch input:checked ~ .track .thumb { transform: translateX(18px); }
/* บนพื้นหลังเข้ม (app-header) — track ปิดใช้ขาวโปร่งแสงแทน เพราะพื้นเข้มมองไม่เห็น track สีเดิม */
.switch.on-dark .track { background: rgba(255, 255, 255, .3); }
.switch.on-dark input:checked ~ .track { background: var(--turmeric-400); }
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.field { margin-bottom: 14px; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--white);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  flex: 1;
  text-align: center;
  padding: 10px 4px 8px;
  font-size: 11px;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.bottom-nav a.active { color: var(--paddy-700); font-weight: 700; }
.bottom-nav .icon { font-size: 20px; }
.bottom-nav .cart-badge {
  position: absolute;
  background: var(--clay-600);
  color: var(--white);
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 5px;
  margin-left: 14px;
  margin-top: -4px;
}

/* ---------- Toasts / alerts ---------- */
.alert {
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13.5px;
  margin-bottom: 14px;
}
.alert.error { background: #fbe4dc; color: var(--clay-600); }
.alert.info { background: var(--paddy-50); color: var(--paddy-700); }

/* ---------- Login / auth screens ---------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 24px;
  background: linear-gradient(180deg, var(--paddy-900) 0%, var(--paddy-900) 240px, var(--cream) 240px);
}
.auth-card {
  background: var(--white);
  border-radius: 16px;
  padding: 24px 20px;
  box-shadow: 0 8px 24px rgba(28,48,24,.12);
}
.auth-logo { text-align: center; color: var(--white); margin-bottom: 28px; }
.auth-logo .mark { font-size: 34px; }
.auth-logo h1 { font-size: 18px; margin: 8px 0 2px; }
.auth-logo p { font-size: 12.5px; margin: 0; color: var(--paddy-100); }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.auth-tabs button {
  flex: 1; padding: 9px; border-radius: 20px; border: 1.5px solid var(--line);
  background: var(--white); font-size: 13px; font-weight: 600; color: var(--ink-soft); cursor: pointer;
}
.auth-tabs button.active { background: var(--paddy-700); color: var(--white); border-color: var(--paddy-700); }
.auth-switch { text-align: center; margin-top: 16px; font-size: 13.5px; color: var(--ink-soft); }
.auth-switch a { color: var(--paddy-700); font-weight: 700; }

/* หัวฟอร์มสมัครสมาชิก — ให้รู้ว่ากำลังกรอกใบสมัคร (ไม่ใช่ช่องเข้าสู่ระบบ) */
.form-head { margin: 0 0 16px; padding: 12px 14px; border-radius: 12px; background: var(--paddy-50); border-left: 4px solid var(--paddy-700); }
.form-head h2 { margin: 0; font-size: 18px; color: var(--paddy-700); }
.form-head p { margin: 4px 0 0; font-size: 13px; color: var(--ink-soft); line-height: 1.5; }

/* ช่องติ๊กยอมรับ/ยินยอมตอนสมัคร — checkbox ใหญ่ 24px ในกรอบที่กดได้ทั้งแถว เห็นชัดว่าต้องติ๊ก */
.check-row { display: flex; align-items: flex-start; gap: 12px; margin: 12px 0; padding: 12px 14px; border: 2px solid var(--line); border-radius: 12px; background: #fff; font-size: 14px; line-height: 1.55; font-weight: 400; cursor: pointer; }
.check-row input[type="checkbox"], .check-row input[type="radio"] { width: 24px; height: 24px; min-width: 24px; margin: 1px 0 0; accent-color: var(--paddy-700); cursor: pointer; }
.check-row:has(input:checked) { border-color: var(--paddy-700); background: var(--paddy-50); }
.check-row .req { color: var(--clay-600); font-weight: 700; white-space: nowrap; }

/* ---------- Product list ---------- */
.product-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.product-row:last-child { border-bottom: none; }
.product-row .meta { flex: 1; min-width: 0; }
.product-row .name { font-weight: 700; margin: 0; }
.product-row .price { color: var(--turmeric-500); font-weight: 700; margin: 2px 0 0; }
.qty-control { display: flex; align-items: center; gap: 10px; }
.qty-control button {
  width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--paddy-700);
  background: var(--white); color: var(--paddy-700); font-size: 16px; font-weight: 700; cursor: pointer;
}
.qty-control span { min-width: 18px; text-align: center; font-weight: 700; }

/* ---------- Product grid (แบบ LINE MAN) — ใช้แทน .product-row ในหน้าเลือกซื้อของลูกค้า ---------- */
.product-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.product-card { display: flex; flex-direction: column; }
.product-card .thumb-wrap { position: relative; }
.product-card .thumb {
  width: 100%; aspect-ratio: 1 / 1; border-radius: 14px; object-fit: cover;
  background: var(--paddy-50); display: block;
}
.product-card .thumb-placeholder {
  width: 100%; aspect-ratio: 1 / 1; border-radius: 14px; background: var(--paddy-50);
  display: flex; align-items: center; justify-content: center; font-size: 30px;
}
.product-card .preorder-flag {
  position: absolute; top: 8px; left: 8px; background: var(--turmeric-400); color: var(--paddy-900);
  font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 20px;
}
.product-card .name { font-size: 13.5px; font-weight: 700; margin: 10px 0 0; line-height: 1.35; }
.product-card .price { font-size: 13.5px; font-weight: 700; color: var(--turmeric-500); margin: 3px 0 0; }
.product-card .preorder-date { font-size: 11.5px; color: var(--clay-600); margin: 2px 0 0; }

/* ปุ่ม +/stepper ลอยมุมขวาล่างของรูป — แตะเพิ่มสินค้าลงตะกร้าได้ทันทีแบบ LINE MAN */
.qty-fab {
  position: absolute; right: -6px; bottom: -6px;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--white); border: 1.5px solid var(--paddy-700);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: var(--paddy-700); line-height: 1;
  box-shadow: 0 2px 6px rgba(28,48,24,.18); cursor: pointer; padding: 0;
}
.qty-fab-stepper {
  position: absolute; right: -6px; bottom: -6px;
  display: flex; align-items: center; gap: 8px;
  background: var(--white); border: 1.5px solid var(--paddy-700); border-radius: 20px;
  padding: 4px 8px; box-shadow: 0 2px 6px rgba(28,48,24,.18);
}
.qty-fab-stepper button {
  border: none; background: none; color: var(--paddy-700); font-size: 16px; font-weight: 700;
  width: 18px; text-align: center; cursor: pointer; padding: 0; line-height: 1;
}
.qty-fab-stepper span { font-size: 12.5px; font-weight: 700; color: var(--ink); min-width: 12px; text-align: center; }

/* ---------- หน้าต่างเลือกตัวเลือกเมนู (bottom sheet) — หน้าร้านฝั่งลูกค้า ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(36,31,24,.45); z-index: 1000; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1001;
  max-width: 560px; margin: 0 auto; max-height: 85vh; overflow-y: auto;
  background: var(--white); border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 24px rgba(28,48,24,.18);
}
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.sheet-title { font-size: 17px; font-weight: 700; margin: 0; line-height: 1.35; }
.sheet-close {
  flex: none; width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid var(--line);
  background: var(--white); color: var(--ink-soft); font-size: 15px; cursor: pointer;
}
.opt-group-title { font-weight: 700; margin: 16px 0 8px; }
.opt-group-title .muted { font-weight: 400; font-size: 13px; }
.opt-choices { display: flex; flex-wrap: wrap; gap: 8px; }
.opt-choice {
  min-height: 42px; padding: 8px 14px; border-radius: 21px; border: 1.5px solid var(--line);
  background: var(--white); color: var(--ink); font: inherit; font-size: 14.5px; cursor: pointer;
}
.opt-choice.selected { border-color: var(--paddy-700); background: var(--paddy-50); color: var(--paddy-900); font-weight: 700; }
.opt-choice .opt-price { color: var(--turmeric-500); font-weight: 700; font-size: 13px; }
.sheet-foot { display: flex; align-items: center; gap: 14px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }

/* ---------- ตั้งตัวเลือกเมนู (หน้าจัดการสินค้าของร้าน) ---------- */
.opt-presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.opt-preset {
  padding: 6px 12px; border-radius: 18px; border: 1.5px dashed var(--paddy-400); background: var(--paddy-50);
  color: var(--paddy-700); font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.opt-edit-group { border: 1.5px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; background: var(--white); }
.opt-edit-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.opt-edit-row input { margin: 0; min-width: 0; padding: 9px 10px; font-size: 14.5px; }
.opt-edit-row .opt-edit-price { flex: 0 0 76px; }
.opt-edit-x {
  flex: none; width: 32px; height: 32px; border-radius: 8px; border: 1.5px solid var(--line);
  background: var(--white); color: var(--ink-soft); cursor: pointer; font-size: 13px;
}
.opt-link { border: none; background: none; color: var(--paddy-700); font: inherit; font-size: 13.5px; font-weight: 600; padding: 4px 0; cursor: pointer; }

/* ---------- รูปย่อร้านค้า (โลโก้/ภาพหน้าร้าน) — ใช้ทั้งในรายการร้านและแถบร้านแนะนำ ---------- */
.shop-thumb {
  width: 48px; height: 48px; border-radius: 10px; object-fit: cover; flex-shrink: 0;
}
.shop-thumb-placeholder {
  width: 48px; height: 48px; border-radius: 10px; background: var(--paddy-50); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}

/* ---------- แถบร้านแนะนำ/โฆษณา — carousel เลื่อนแนวนอนบนหน้าแรก ---------- */
.featured-scroll {
  display: flex; gap: 12px; overflow-x: auto; padding: 0 20px 4px; scrollbar-width: none;
}
.featured-scroll::-webkit-scrollbar { display: none; }
.featured-card { flex: 0 0 152px; display: flex; flex-direction: column; }
.featured-card .cover {
  position: relative; width: 152px; height: 110px; border-radius: 14px; overflow: hidden;
  background: linear-gradient(135deg, var(--paddy-400), var(--paddy-700));
}
.featured-card .cover img { width: 100%; height: 100%; object-fit: cover; }
.featured-card .ad-flag {
  position: absolute; top: 8px; left: 8px; background: var(--turmeric-400); color: var(--paddy-900);
  font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 20px;
}
.featured-card .name { font-size: 13.5px; font-weight: 700; margin: 8px 0 0; color: var(--paddy-900); }
.featured-card .sub { font-size: 11.5px; color: var(--ink-soft); margin: 2px 0 0; }
.rating { font-weight: 700; color: var(--ink); }
.featured-label {
  font-size: 10px; font-weight: 700; color: var(--clay-600); background: #f5e9e4;
  padding: 3px 8px; border-radius: 20px; letter-spacing: .3px; white-space: nowrap;
}

/* ---------- Order status timeline ---------- */
.status-pill {
  display: inline-block; font-size: 12px; font-weight: 700; padding: 4px 12px;
  border-radius: 20px; background: var(--paddy-50); color: var(--paddy-700);
}
.status-pill.cancelled { background: #fbe4dc; color: var(--clay-600); }
.status-pill.pending { background: #fbeecb; color: var(--turmeric-500); }

/* ---------- รายละเอียดออเดอร์ (รายการอาหาร / หมายเหตุ / ผู้ติดต่อ) ---------- */
.order-items {
  width: 100%; display: flex; flex-direction: column; gap: 3px;
  background: var(--paddy-50); border-radius: 10px; padding: 8px 10px; font-size: 14px;
}
.order-items .row-between { align-items: flex-start; gap: 10px; }
.order-items .row-between > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.order-items .row-between > span:last-child { white-space: nowrap; }
.order-note {
  width: 100%; margin: 0; background: #fbeecb; color: #6b4a06; border-radius: 10px;
  padding: 6px 10px; font-size: 14px; overflow-wrap: anywhere;
}
.order-contact { width: 100%; margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.order-contact a { color: var(--paddy-700); font-weight: 700; }

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--line); margin: 14px 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.muted { color: var(--ink-soft); font-size: 13px; }
.loading { text-align: center; padding: 40px 0; color: var(--ink-soft); }
