/* ============================================================================
   Community Commerce Platform (CCP) — Design System v2
   Grid: 8pt · Radius: 16px · Primary: #2563EB · Body: 14px
   Spec: design.md (Apple HIG + Material 3 + Grab Mobile UX)
   ============================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* ── Brand Colors ── */
  --color-primary:        #2563EB;
  --color-primary-hover:  #1D4ED8;
  --color-primary-light:  #EFF6FF;
  --color-primary-muted:  #BFDBFE;

  --color-success:        #16A34A;
  --color-success-light:  #F0FDF4;
  --color-warning:        #F59E0B;
  --color-warning-light:  #FFFBEB;
  --color-danger:         #DC2626;
  --color-danger-light:   #FEF2F2;

  /* ── Grays ── */
  --gray-50:  #F8FAFC;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --gray-900: #111827;

  /* ── Text ── */
  --text-primary:    #111827;
  --text-secondary:  #6B7280;
  --text-muted:      #9CA3AF;
  --text-on-primary: #FFFFFF;

  /* ── Surfaces ── */
  --surface-page:   #FFFFFF;
  --surface-card:   #FFFFFF;
  --surface-raised: #F8FAFC;
  --surface-input:  #F8FAFC;

  /* ── Borders ── */
  --border-default: #E5E7EB;
  --border-strong:  #D1D5DB;
  --border-focus:   #2563EB;

  /* ── Shadows (soft only — no heavy drop shadows) ── */
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08), 0 2px 8px rgba(0,0,0,0.04);
  --shadow-xl: 0 16px 40px rgba(0,0,0,0.10), 0 4px 12px rgba(0,0,0,0.04);

  /* ── Radius (16px everywhere — cards, buttons, search, images) ── */
  --radius-sm:   8px;
  --radius-md:  12px;
  --radius-lg:  16px;   /* primary — cards, buttons, search */
  --radius-xl:  20px;
  --radius-full: 9999px;

  /* ── Spacing (8pt grid: 4/8/16/24/32/48) ── */
  --space-0:  4px;
  --space-1:  8px;
  --space-2:  16px;
  --space-3:  24px;
  --space-4:  32px;
  --space-5:  40px;
  --space-6:  48px;

  /* ── Typography Scale ──
     Title   24px 700
     Section 18px 600
     Card    16px 600
     Body    14px 400
     Caption 12px 400
  ── */
  --font-sans:      'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  --font-size-xs:   12px;   /* caption */
  --font-size-sm:   13px;   /* small label */
  --font-size-base: 14px;   /* body */
  --font-size-md:   16px;   /* card title */
  --font-size-lg:   18px;   /* section */
  --font-size-xl:   24px;   /* page title */

  /* ── Transitions ── */
  --ease-default:  cubic-bezier(0.4,0,0.2,1);
  --duration-fast: 120ms;
  --duration-base: 200ms;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--surface-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── App Container (mobile-first, max 480px) ── */
.app-container {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface-page);
  position: relative;
  box-shadow: var(--shadow-xl);
}

/* ── Page Header ── */
.page-header {
  background: var(--color-primary);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid rgba(255,255,255,0.10);
}
.page-header h1 {
  font-size: var(--font-size-md);
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.page-header .subtitle {
  font-size: var(--font-size-xs);
  color: rgba(255,255,255,0.72);
  margin-top: 2px;
}

/* ── Typography Utilities ── */
.text-title   { font-size: var(--font-size-xl); font-weight: 700; color: var(--text-primary); letter-spacing: -0.02em; }
.text-section { font-size: var(--font-size-lg); font-weight: 600; color: var(--text-primary); letter-spacing: -0.01em; }
.text-card    { font-size: var(--font-size-md); font-weight: 600; color: var(--text-primary); }
.text-body    { font-size: var(--font-size-base); font-weight: 400; color: var(--text-primary); }
.text-caption { font-size: var(--font-size-xs);  font-weight: 400; color: var(--text-secondary); }
.text-label   { font-size: 11px; font-weight: 600; color: var(--text-muted); letter-spacing: 0.06em; text-transform: uppercase; }

/* ── Cards ── */
.glass-card, .card {
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

/* ── Section Label ── */
.section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

/* ── Form Elements ── */
.form-group  { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 13px 16px;
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--border-default);
  background: var(--surface-input);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  line-height: 1.5;
  transition: border-color var(--duration-base) var(--ease-default),
              box-shadow var(--duration-base) var(--ease-default);
}
.form-input::placeholder { color: var(--text-muted); }
.form-input:focus {
  outline: none;
  border-color: var(--border-focus);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

/* ── Search Bar ── */
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--border-default);
  background: var(--surface-input);
  transition: border-color var(--duration-base), box-shadow var(--duration-base);
}
.search-bar:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
.search-bar input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: var(--font-size-base);
  font-family: var(--font-sans);
  color: var(--text-primary);
}
.search-bar input::placeholder { color: var(--text-muted); }

/* ── Buttons (min-height 48px per design spec) ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 20px;
  min-height: 48px;
  border-radius: var(--radius-lg);
  border: none;
  font-weight: 600;
  font-size: var(--font-size-base);
  font-family: var(--font-sans);
  cursor: pointer;
  width: 100%;
  transition: all var(--duration-fast) var(--ease-default);
  letter-spacing: -0.01em;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 1px 3px rgba(37,99,235,0.30), 0 1px 2px rgba(37,99,235,0.20);
}
.btn-primary:hover { background: var(--color-primary-hover); }

.btn-secondary {
  background: var(--surface-raised);
  color: var(--text-primary);
  border: 1.5px solid var(--border-default);
}
.btn-secondary:hover { background: var(--gray-100); }

.btn-success {
  background: var(--color-success);
  color: #fff;
  box-shadow: 0 1px 3px rgba(22,163,74,0.25);
}
.btn-success:hover { filter: brightness(1.05); }

.btn-danger {
  background: var(--color-danger);
  color: #fff;
  box-shadow: 0 1px 3px rgba(220,38,38,0.25);
}
.btn-danger:hover { filter: brightness(1.05); }

.btn-ghost {
  background: transparent;
  color: var(--color-primary);
  border: 1.5px solid var(--color-primary-muted);
}
.btn-ghost:hover { background: var(--color-primary-light); }

/* Small button variant */
.btn-sm {
  min-height: 36px;
  padding: 8px 16px;
  font-size: var(--font-size-sm);
  border-radius: var(--radius-md);
}

/* ── Icon Button (header actions) ── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  cursor: pointer;
  transition: background var(--duration-fast);
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: rgba(255,255,255,0.25); }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: 600;
  letter-spacing: 0.01em;
}
.badge-primary { background: var(--color-primary-light); color: var(--color-primary); }
.badge-success { background: var(--color-success-light); color: var(--color-success); }
.badge-warning { background: var(--color-warning-light); color: var(--color-warning); }
.badge-danger  { background: var(--color-danger-light);  color: var(--color-danger); }
.badge-gray    { background: var(--gray-100);             color: var(--gray-600); }

/* ── Tab Navigation ── */
.tab-bar {
  display: flex;
  background: var(--gray-100);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}
.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 9px 6px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.tab-btn.active {
  background: #fff;
  color: var(--color-primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* ── Bottom Navigation (5-tab, frosted glass) ── */
.bottom-nav {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: rgba(255,255,255,0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-default);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 12px;
  min-width: 56px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--duration-fast);
  border: none;
  background: transparent;
  font-family: var(--font-sans);
  -webkit-tap-highlight-color: transparent;
}
.nav-item.active { color: var(--color-primary); font-weight: 600; }
.nav-icon { display: flex; align-items: center; justify-content: center; position: relative; }
.nav-badge {
  position: absolute;
  top: -4px;
  right: -6px;
  min-width: 16px;
  height: 16px;
  background: var(--color-danger);
  color: #fff;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 1.5px solid #fff;
}

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--border-default);
  margin: 16px 0;
}

/* ── Empty State ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 24px;
  color: var(--text-muted);
  text-align: center;
}
.empty-state-icon {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}
.empty-state p { font-size: var(--font-size-sm); line-height: 1.6; }

/* ── Loading Spinner ── */
.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast notification ── */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  background: var(--gray-900);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-lg);
  font-size: var(--font-size-sm);
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  white-space: nowrap;
  pointer-events: none;
  animation: toastIn 0.2s var(--ease-default);
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Animations ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.animate-fade-in { animation: fadeIn 0.25s var(--ease-default) forwards; }

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.animate-slide-up { animation: slideUp 0.28s cubic-bezier(0.16,1,0.3,1) forwards; }

@keyframes scaleIn {
  from { transform: scale(0.96); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.animate-scale-in { animation: scaleIn 0.18s cubic-bezier(0.16,1,0.3,1) forwards; }

/* ── Image containers ── */
.img-card {
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface-raised);
}
.img-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ── Operator scrollable tab bar ── */
.op-tab-bar {
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--gray-100);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
  scrollbar-width: none;
}
.op-tab-bar::-webkit-scrollbar { display: none; }
.op-tab-btn { flex-shrink: 0; min-width: 72px; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }

/* ── กันมือถือ auto-zoom ตอนแตะช่องกรอก ──
   iOS/Android ซูมเข้าเองเมื่อ input font-size < 16px แล้วค้างซูมหลัง login
   บังคับ 16px เฉพาะจอมือถือ (override inline style เดิมที่ 12-14px) */
@media (max-width: 767px) {
  input, select, textarea { font-size: 16px !important; }
}

/* ── ใบออเดอร์สำหรับพิมพ์ (กระดาษความร้อน 58mm) ── */
#order-receipt { display: none; }
@media print {
  body * { visibility: hidden !important; }
  #order-receipt, #order-receipt * { visibility: visible !important; }
  #order-receipt {
    display: block !important;
    position: absolute; left: 0; top: 0;
    width: 58mm; padding: 2mm;
    font-family: 'Sarabun', 'Tahoma', monospace;
    font-size: 11px; color: #000; background: #fff;
  }
  #order-receipt .rc-hr { border: none; border-top: 1px dashed #000; margin: 4px 0; }
  #order-receipt .rc-row { display: flex; justify-content: space-between; gap: 4px; }
  #order-receipt .rc-center { text-align: center; }
}
