/* Preorder · Brand: mint #58fcc6 + magenta #fd65e6 */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --mint: #58fcc6;
  --mint-dark: #2dd4a8;
  --mint-darker: #14b88e;
  --mint-50: #f0fdf9;
  --mint-100: #d4faec;
  --mint-200: #a5f3d8;
  --magenta: #fd65e6;
  --magenta-dark: #e845ce;
  --magenta-darker: #c026a8;
  --magenta-50: #fef0fb;
  --magenta-100: #fdd9f5;
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --emerald-50: #ecfdf5;
  --emerald-500: #10b981;
  --emerald-600: #059669;
  --emerald-700: #047857;
  --red-50: #fef2f2;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --blue-50: #eff6ff;
  --amber-50: #fffbeb;
  --amber-500: #f59e0b;
  --amber-600: #d97706;
}

body {
  font-family: 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--slate-900);
  font-size: 14px;
  line-height: 1.55;
  background:
    radial-gradient(circle at 0% 0%, var(--mint-50) 0%, transparent 40%),
    radial-gradient(circle at 100% 100%, var(--magenta-50) 0%, transparent 40%),
    var(--slate-50);
  min-height: 100vh;
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
}

.hidden { display: none !important; }

/* ─── Topbar ─────────────────────────────────── */
.topbar {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--slate-200);
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--mint) 0%, var(--magenta) 100%);
  color: white; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px -2px rgba(253, 101, 230, 0.3);
}
.brand-text strong { display: block; font-size: 15px; font-weight: 700; color: var(--slate-900); }
.brand-text small { display: block; font-size: 11px; color: var(--slate-500); }

.topbar-actions { display: flex; gap: 6px; }

.btn-ghost-sm {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 10px;
  background: white;
  color: var(--slate-700);
  border: 1px solid var(--slate-200);
  border-radius: 8px;
  font-family: inherit; font-size: 12px; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
}
.btn-ghost-sm:hover { background: var(--mint-50); border-color: var(--mint); color: var(--mint-darker); }

/* ─── Stats bar ──────────────────────────────── */
.stats-bar {
  display: flex; gap: 12px; align-items: center;
  padding: 16px;
  flex-wrap: wrap;
}
.stat {
  display: flex; flex-direction: column;
  background: white;
  border: 1px solid var(--slate-200);
  border-radius: 10px;
  padding: 8px 14px;
  min-width: 80px;
}
.stat-num { font-size: 18px; font-weight: 700; color: var(--slate-900); line-height: 1; }
.stat-lbl { font-size: 11px; color: var(--slate-500); margin-top: 2px; }
.stat-sync {
  margin-left: auto;
  font-size: 11px;
  color: var(--slate-500);
  display: flex; align-items: center; gap: 4px;
}

/* ─── Tabnav ─────────────────────────────────── */
.tabs-bar {
  display: flex; gap: 4px; padding: 0 16px 8px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.tabnav {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  background: white;
  border: 1px solid var(--slate-200);
  border-radius: 8px;
  color: var(--slate-700);
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
  white-space: nowrap;
}
.tabnav:hover { background: var(--slate-50); }
.tabnav.active {
  background: linear-gradient(135deg, var(--mint) 0%, var(--magenta) 100%);
  color: white;
  border-color: transparent;
  font-weight: 600;
  box-shadow: 0 2px 8px -2px rgba(253, 101, 230, 0.4);
}

.cart-badge {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--magenta-darker); color: white;
  border-radius: 10px;
  min-width: 20px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 700;
}
.tabnav.active .cart-badge { background: rgba(255,255,255,0.3); color: white; }

/* ─── Filter bar ─────────────────────────────── */
.filter-bar {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  background: white;
  border: 1px solid var(--slate-200);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 12px;
}
@media (max-width: 768px) {
  .filter-bar { grid-template-columns: 1fr 1fr; }
}
.search-input { position: relative; }
.search-input .icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--slate-400); pointer-events: none;
}
.search-input input {
  width: 100%; padding: 8px 12px 8px 36px;
  border: 1px solid var(--slate-200);
  border-radius: 8px;
  font-family: inherit; font-size: 13px;
}
.search-input input:focus { outline: none; border-color: var(--mint-dark); box-shadow: 0 0 0 3px rgba(45, 212, 168, 0.15); }
.filter-bar select {
  padding: 8px 12px;
  border: 1px solid var(--slate-200);
  border-radius: 8px;
  font-family: inherit; font-size: 13px;
  background: white;
  cursor: pointer;
}
.filter-bar select:focus { outline: none; border-color: var(--mint-dark); }
.checkbox { display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; cursor: pointer; font-size: 13px; user-select: none; }
.checkbox input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--mint-darker); }

/* ─── Views ──────────────────────────────────── */
.view { display: none; padding-bottom: 60px; }
.view.active { display: block; animation: fadeIn 0.2s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.view h3 { font-size: 16px; font-weight: 600; margin-bottom: 12px; color: var(--slate-800); }
.view-help { font-size: 13px; color: var(--slate-600); margin-bottom: 12px; padding: 0 4px; }
.loading { text-align: center; padding: 40px; color: var(--slate-500); }

/* ─── Products list ─────────────────────────── */
.products-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 10px;
}
.product-card {
  background: white;
  border: 1px solid var(--slate-200);
  border-radius: 12px;
  padding: 14px;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.product-card:hover { border-color: var(--mint); box-shadow: 0 4px 16px -4px rgba(20, 184, 142, 0.2); }
.product-card.out-of-stock { opacity: 0.55; }

.pc-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.pc-name { font-size: 13px; font-weight: 600; color: var(--slate-900); line-height: 1.4; flex: 1; }
.pc-supplier {
  font-size: 10px;
  color: var(--magenta-darker);
  background: var(--magenta-50);
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}
.pc-meta {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  font-size: 11px;
  color: var(--slate-500);
}
.pc-tag {
  background: var(--slate-100);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
}
.pc-tag.warranty { background: var(--mint-50); color: var(--mint-darker); }
.pc-bottom {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 4px;
}
.pc-price {
  font-size: 18px;
  font-weight: 800;
  color: var(--mint-darker);
  font-family: ui-monospace, 'SF Mono', Monaco, monospace;
}
.pc-stock { font-size: 11px; font-weight: 600; }
.pc-stock.in { color: var(--emerald-600); }
.pc-stock.out { color: var(--red-600); }
.pc-stock.low { color: var(--amber-600); }

.pc-actions { display: flex; gap: 6px; margin-top: 6px; }
.pc-btn {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--slate-200);
  border-radius: 6px;
  background: white;
  font-family: inherit; font-size: 12px; font-weight: 500;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  transition: all 0.15s;
  color: var(--slate-700);
}
.pc-btn:hover { background: var(--mint-50); border-color: var(--mint); color: var(--mint-darker); }
.pc-btn-buy {
  background: linear-gradient(135deg, var(--magenta) 0%, var(--magenta-darker) 100%);
  color: white;
  border: none;
  font-weight: 600;
}
.pc-btn-buy:hover { box-shadow: 0 2px 8px -2px rgba(232, 69, 206, 0.5); color: white; }
.pc-btn:disabled, .pc-btn-buy:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Compare groups ─────────────────────────── */
.groups-list {
  display: flex; flex-direction: column; gap: 8px;
}
.group-card {
  background: white;
  border: 1px solid var(--slate-200);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  transition: all 0.15s;
  display: grid;
  grid-template-columns: 1fr auto auto auto auto;
  gap: 12px;
  align-items: center;
}
.group-card:hover { border-color: var(--magenta); box-shadow: 0 4px 16px -4px rgba(192, 38, 168, 0.2); }
.group-name { font-size: 14px; font-weight: 600; color: var(--slate-900); }
.group-cat { font-size: 11px; color: var(--slate-500); margin-top: 2px; }
.group-suppliers {
  background: var(--mint-100); color: var(--mint-darker);
  font-weight: 700; font-size: 11px;
  padding: 4px 10px; border-radius: 8px;
}
.group-stock { font-size: 11px; color: var(--slate-600); }
.group-price-range {
  font-family: ui-monospace, 'SF Mono', Monaco, monospace;
  font-weight: 700; color: var(--mint-darker);
  font-size: 13px;
  text-align: right;
}
.group-arrow { color: var(--slate-400); }

/* ─── Cart ───────────────────────────────────── */
.cart-item {
  display: flex; gap: 10px; align-items: center;
  background: white;
  border: 1px solid var(--slate-200);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
}
.cart-item-info { flex: 1; }
.cart-item-name { font-size: 13px; font-weight: 600; color: var(--slate-900); }
.cart-item-meta { font-size: 11px; color: var(--slate-500); margin-top: 2px; }
.cart-qty {
  display: flex; align-items: center; gap: 4px;
  background: var(--slate-50);
  border-radius: 6px;
  padding: 2px;
}
.cart-qty button {
  width: 24px; height: 24px;
  border: none; background: white;
  border-radius: 4px; cursor: pointer;
  font-weight: 700; font-size: 14px;
  color: var(--slate-700);
}
.cart-qty input {
  width: 36px; text-align: center;
  border: none; background: transparent;
  font-family: inherit; font-size: 13px; font-weight: 600;
}
.cart-item-price {
  font-family: ui-monospace, monospace;
  font-weight: 700; color: var(--mint-darker);
  font-size: 14px;
  min-width: 60px;
  text-align: right;
}
.cart-remove {
  background: var(--red-50); color: var(--red-600);
  border: none; border-radius: 6px;
  padding: 4px 8px; cursor: pointer;
  font-family: inherit; font-size: 11px; font-weight: 500;
}
.cart-summary {
  position: sticky; bottom: 12px;
  background: white;
  border: 2px solid var(--magenta);
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 16px;
  display: flex; gap: 16px; align-items: center;
  box-shadow: 0 8px 24px -8px rgba(232, 69, 206, 0.3);
}
.cart-total { flex: 1; }
.cart-total span { font-size: 12px; color: var(--slate-600); display: block; }
.cart-total strong { font-size: 22px; color: var(--magenta-darker); font-family: ui-monospace, monospace; }

/* ─── History ────────────────────────────────── */
.history-item {
  background: white;
  border: 1px solid var(--slate-200);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.history-name { font-weight: 600; font-size: 13px; }
.history-meta { font-size: 11px; color: var(--slate-500); margin-top: 2px; }
.history-amount { font-family: ui-monospace, monospace; font-weight: 700; color: var(--mint-darker); }
.history-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  margin-top: 4px;
}
.history-status.success { background: var(--emerald-50); color: var(--emerald-700); }
.history-status.failed { background: var(--red-50); color: var(--red-600); }
.history-status.pending { background: var(--amber-50); color: var(--amber-600); }

/* ─── Buttons (general) ──────────────────────── */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px;
  background: linear-gradient(135deg, var(--mint-dark) 0%, var(--mint-darker) 100%);
  color: white; border: none; border-radius: 10px;
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all 0.15s;
  box-shadow: 0 2px 8px -2px rgba(45, 212, 168, 0.4);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 14px -2px rgba(45, 212, 168, 0.5); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary.btn-magenta {
  background: linear-gradient(135deg, var(--magenta) 0%, var(--magenta-darker) 100%);
  box-shadow: 0 2px 8px -2px rgba(232, 69, 206, 0.4);
}

/* ─── Modal ──────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
}
.modal-card {
  position: relative; z-index: 1;
  background: white;
  border-radius: 16px;
  width: 100%; max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 48px rgba(0,0,0,0.15);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--slate-200);
  position: sticky; top: 0; background: white;
  border-radius: 16px 16px 0 0;
}
.modal-head h2 { font-size: 15px; font-weight: 700; }
.modal-close {
  width: 28px; height: 28px;
  border: none; background: var(--slate-100);
  border-radius: 8px; cursor: pointer;
  font-size: 18px; color: var(--slate-600);
  display: flex; align-items: center; justify-content: center;
}
.modal-body { padding: 16px 20px; }

/* Modal group: option rows */
.group-option {
  display: flex; gap: 10px; align-items: center;
  padding: 10px 12px;
  background: var(--slate-50);
  border: 1px solid var(--slate-200);
  border-radius: 10px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.group-option:hover { background: var(--mint-50); border-color: var(--mint); }
.group-option.selected { background: var(--mint-50); border-color: var(--mint-dark); }
.go-info { flex: 1; }
.go-name { font-size: 13px; font-weight: 600; color: var(--slate-900); }
.go-meta { font-size: 11px; color: var(--slate-500); margin-top: 2px; }
.go-price { font-family: ui-monospace, monospace; font-weight: 700; color: var(--mint-darker); font-size: 14px; }
.go-stock { font-size: 11px; font-weight: 600; }
.go-stock.in { color: var(--emerald-600); }
.go-stock.out { color: var(--red-600); }
.go-stock.low { color: var(--amber-600); }

.modal-buy-row {
  display: flex; justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--slate-100);
  font-size: 13px;
}
.modal-buy-row strong { color: var(--slate-900); }
.modal-buy-row span { color: var(--slate-600); }
.modal-buy-total {
  display: flex; justify-content: space-between;
  padding: 12px 0 16px;
  font-size: 15px;
  font-weight: 700;
}
.modal-buy-total strong { color: var(--magenta-darker); }

/* Wallet modal */
.wallet-row {
  display: flex; justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--slate-50);
  border: 1px solid var(--slate-200);
  border-radius: 10px;
  margin-bottom: 6px;
}
.wallet-name { font-weight: 600; font-size: 13px; }
.wallet-balance { font-family: ui-monospace, monospace; font-weight: 700; color: var(--mint-darker); }
.wallet-balance.zero { color: var(--red-500); }
.wallet-balance.error { color: var(--amber-600); font-size: 12px; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--slate-900); color: white;
  padding: 10px 20px; border-radius: 10px;
  font-size: 13px; font-weight: 500;
  z-index: 200; white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  transition: opacity 0.3s;
}
.toast.success { background: var(--emerald-600); }
.toast.error { background: var(--red-600); }
.toast.info { background: var(--slate-800); }

/* Footer */
.footer {
  text-align: center; padding: 24px;
  color: var(--slate-400); font-size: 12px;
}

@media (max-width: 640px) {
  .products-list { grid-template-columns: 1fr; }
  .group-card { grid-template-columns: 1fr auto; gap: 8px; }
  .group-suppliers, .group-stock, .group-arrow { display: none; }
  .filter-bar { grid-template-columns: 1fr; }
}
