:root {
  --tint: 37, 99, 235;
  --tint-2: 6, 182, 212;
  --bg-1: #eef8ff;
  --bg-2: #dcefff;
  --bg-3: #cbe6fb;
  --ink: #0b2942;
  --ink-dim: #4f7089;
  --ink-dimmer: #85a3b9;
  --surface: rgba(255, 255, 255, 0.62);
  --surface-soft: rgba(255, 255, 255, 0.42);
  --border: rgba(var(--tint), 0.16);
  --sky: #38bdf8;
  --blue: #2563eb;
  --teal: #06b6d4;
  --indigo: #6366f1;
  --green: #16a34a;
  --red: #e11d48;
  --amber: #f59e0b;
  --grad: linear-gradient(135deg, #2563eb, #06b6d4);
  --grad-warm: linear-gradient(135deg, #f59e0b, #fb923c);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --shadow-soft: 0 8px 30px rgba(var(--tint), 0.12);
  --shadow-lift: 0 20px 45px rgba(var(--tint), 0.22);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  /* iOS Safari นับ 100vh รวมแถบเบราว์เซอร์ ทำให้เนื้อหาล้นจอ dvh วัดตามพื้นที่จริง */
  min-height: 100dvh;
  background: radial-gradient(ellipse at top, var(--bg-1) 0%, var(--bg-2) 55%, var(--bg-3) 100%);
  color: var(--ink);
  font-family: 'Prompt', system-ui, -apple-system, sans-serif;
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* ===== ไอคอน SVG หลายสี (ใช้แทนอิโมจิ) ===== */
.ic {
  width: 1.15em;
  height: 1.15em;
  flex-shrink: 0;
  vertical-align: -0.2em;
  /* ไอคอนที่ใช้ currentColor (เช่น กากบาท เครื่องหมายถูก) จะรับสีจากข้อความรอบๆ */
  color: inherit;
}
.ic-sm { width: 1em; height: 1em; }
.ic-lg { width: 1.6em; height: 1.6em; vertical-align: -0.35em; }
/* ไอคอนขนาดใหญ่ที่ใช้เป็นภาพประกอบ ไม่ใช่ประกอบข้อความ */
.ic-hero { width: 44px; height: 44px; display: block; margin: 0 auto; }
.ic-empty { width: 56px; height: 56px; display: block; margin: 0 auto 12px; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

/* ===== Floating watercolor blobs ===== */
.bg-blobs {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  /* บังคับให้เป็นเลเยอร์ของตัวเอง กัน iOS Safari ทิ้งรอยเปื้อนตอนเลื่อนจอ
     เพราะ position:fixed คู่กับ filter:blur ขนาดใหญ่ */
  transform: translateZ(0);
}
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(85px);
  opacity: 0.55;
  mix-blend-mode: multiply;
  animation: float 20s ease-in-out infinite;
}
.blob-a {
  width: 500px; height: 500px;
  background: #7dd3fc;
  top: -140px; left: -110px;
  animation-duration: 23s;
}
.blob-b {
  width: 440px; height: 440px;
  background: #38bdf8;
  bottom: -150px; right: -90px;
  animation-duration: 27s;
  animation-delay: -6s;
}
.blob-c {
  width: 380px; height: 380px;
  background: #2dd4bf;
  top: 42%; left: 58%;
  animation-duration: 21s;
  animation-delay: -12s;
}
.blob-d {
  width: 300px; height: 300px;
  background: #60a5fa;
  top: 8%; right: 12%;
  animation-duration: 25s;
  animation-delay: -3s;
}
@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(40px, -30px) scale(1.08); }
  66% { transform: translate(-30px, 25px) scale(0.94); }
}

/* ===== Glass surface ===== */
/* เส้นไฮไลต์บาง ๆ ที่ขอบบนด้านใน ทำให้พื้นผิวดูเป็นกระจกจริงขึ้นมาก (ยืมจาก kosame) */
.glass {
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft), inset 0 1px rgba(255, 255, 255, 0.9);
}

/* ===== Buttons ===== */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 15px;
  padding: 12px 22px;
  border-radius: var(--radius-md);
  transition: transform 0.18s cubic-bezier(.34,1.56,.64,1), box-shadow 0.25s ease, filter 0.2s ease;
  color: var(--ink);
}
.btn:active { transform: scale(0.96); }

.btn-primary {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 8px 24px rgba(var(--tint), 0.32);
}
.btn-primary:hover { filter: brightness(1.06); transform: translateY(-2px); box-shadow: 0 12px 30px rgba(var(--tint), 0.4); }

.btn-warm {
  background: var(--grad-warm);
  color: #fff;
  box-shadow: 0 8px 24px rgba(245, 158, 11, 0.32);
}
.btn-warm:hover { filter: brightness(1.06); transform: translateY(-2px); }

.btn-danger {
  background: linear-gradient(135deg, #fb7185, #e11d48);
  color: #fff;
  box-shadow: 0 8px 24px rgba(225, 29, 72, 0.3);
}
.btn-danger:hover { filter: brightness(1.08); transform: translateY(-2px); }

.btn-ghost {
  background: rgba(var(--tint), 0.08);
  border: 1px solid var(--border);
  color: var(--ink);
}
.btn-ghost:hover { background: rgba(var(--tint), 0.14); transform: translateY(-2px); }

.btn-block { width: 100%; }
.plus { font-size: 18px; font-weight: 800; }

.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: rgba(var(--tint), 0.1);
  color: var(--ink);
  font-size: 15px;
  transition: transform 0.15s ease, background 0.2s ease;
}
.icon-btn:hover { background: rgba(var(--tint), 0.2); transform: scale(1.08); }
.icon-btn.ghost { background: transparent; }
.icon-btn.ghost:hover { background: rgba(var(--tint), 0.12); }
.icon-btn.danger:hover { background: rgba(225, 29, 72, 0.18); }
.icon-btn.on-dark { background: rgba(255,255,255,0.25); color: #fff; }
.icon-btn.on-dark:hover { background: rgba(255,255,255,0.4); }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ===== Login ===== */
.login-screen {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  padding: 40px 32px;
  text-align: center;
  animation: pop-in 0.5s cubic-bezier(.34,1.56,.64,1);
}
.login-icon {
  font-size: 44px;
  margin-bottom: 8px;
  animation: bob 3s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.login-title {
  font-size: 26px;
  font-weight: 800;
  margin: 0 0 6px;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.login-sub {
  color: var(--ink-dim);
  font-size: 13.5px;
  margin: 0 0 28px;
  line-height: 1.6;
}
.eye-btn {
  position: absolute;
  right: 6px;
  top: 8px;
  background: transparent;
}
.error-text {
  color: var(--red);
  font-size: 13px;
  margin: -8px 0 16px;
  text-align: left;
}

/* ===== Floating label fields ===== */
.field {
  position: relative;
  margin-bottom: 20px;
  text-align: left;
}
.field input, .field textarea {
  width: 100%;
  background: rgba(255,255,255,0.65);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 14px 8px;
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
  resize: vertical;
}
.field textarea { padding-top: 20px; min-height: 56px; }
.field input:focus, .field textarea:focus {
  border-color: var(--blue);
  background: rgba(var(--tint), 0.06);
}
.field label {
  position: absolute;
  left: 14px;
  top: 15px;
  color: var(--ink-dimmer);
  font-size: 15px;
  pointer-events: none;
  transition: all 0.18s ease;
  background: transparent;
}
.field input:focus + label,
.field input:not(:placeholder-shown) + label,
.field textarea:focus + label,
.field textarea:not(:placeholder-shown) + label {
  top: 4px;
  font-size: 11px;
  color: var(--teal);
}
.field.span-2 { grid-column: span 2; }

/* ===== App shell ===== */
.app {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 80px;
  animation: fade-in 0.5s ease;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-emoji {
  font-size: 34px;
  filter: drop-shadow(0 4px 12px rgba(var(--tint),0.35));
  animation: bob 4s ease-in-out infinite;
}
.brand h1 { margin: 0; font-size: 22px; font-weight: 800; color: var(--ink); }
.brand p { margin: 2px 0 0; color: var(--ink-dim); font-size: 13px; }

/* ===== Navigation ===== */
.main-nav { display: flex; gap: 4px; }
.nav-tab {
  display: flex; align-items: center; gap: 7px;
  border: none; background: transparent; cursor: pointer;
  font-family: inherit; font-weight: 600; font-size: 13.5px;
  color: var(--ink-dim);
  padding: 10px 16px;
  border-radius: 999px;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.nav-tab .nav-icon { font-size: 16px; }
.nav-tab:hover { color: var(--ink); background: rgba(var(--tint),0.08); }
.nav-tab.active { background: var(--grad); color: #fff; box-shadow: 0 6px 16px rgba(var(--tint),0.3); }

.main-nav-top {
  background: rgba(255,255,255,0.45);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}

.main-nav-bottom {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 60;
  justify-content: space-around;
  gap: 0;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-top: 1px solid var(--border);
  box-shadow: 0 -8px 24px rgba(var(--tint),0.12);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
}
.main-nav-bottom .nav-tab {
  flex-direction: column;
  gap: 2px;
  flex: 1;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  font-size: 11px;
}
.main-nav-bottom .nav-tab .nav-icon { font-size: 20px; }
.main-nav-bottom .nav-tab.active { box-shadow: none; background: rgba(var(--tint),0.12); color: var(--blue); }

.page { animation: fade-in 0.35s ease; }

/* ===== Stats ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 24px;
}
.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px;
  animation: fade-in-up 0.5s ease both;
  animation-delay: calc(var(--i) * 0.08s);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lift); }
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.stat-icon-cost { background: linear-gradient(135deg, rgba(var(--tint),0.28), rgba(var(--tint),0.08)); }
.stat-icon-revenue { background: linear-gradient(135deg, rgba(var(--tint-2),0.3), rgba(var(--tint-2),0.08)); }
.stat-icon-profit { background: linear-gradient(135deg, rgba(22,163,74,0.28), rgba(22,163,74,0.08)); }
.stat-icon-count { background: linear-gradient(135deg, rgba(99,102,241,0.28), rgba(99,102,241,0.08)); }
.stat-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stat-label { font-size: 12.5px; color: var(--ink-dim); white-space: nowrap; }
.stat-value { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); }

/* ===== Charts (หน้าแรก) ===== */
.charts-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 18px;
  margin-bottom: 26px;
}
.chart-card {
  padding: 20px 22px;
  animation: fade-in-up 0.5s ease both;
  animation-delay: 0.12s;
}
.chart-head h3 { margin: 0 0 2px; font-size: 15px; font-weight: 700; color: var(--ink); }
.chart-head p { margin: 0 0 16px; font-size: 12px; color: var(--ink-dim); }
.chart-body { position: relative; }
.chart-empty { font-size: 13px; color: var(--ink-dimmer); text-align: center; padding: 46px 10px; }

.chart-hero { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 30px 10px; text-align: center; }
.chart-hero-label { font-size: 12px; color: var(--ink-dim); }
.chart-hero-value { font-size: 28px; font-weight: 800; color: var(--green); font-variant-numeric: tabular-nums; }
.chart-hero-value.negative { color: var(--red); }
.chart-hero-hint { font-size: 11.5px; color: var(--ink-dimmer); margin-top: 4px; }

.trend-svg { width: 100%; height: auto; display: block; overflow: visible; cursor: crosshair; }
.trend-area { fill: rgba(var(--tint), 0.14); stroke: none; }
.trend-line { fill: none; stroke: var(--blue); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.trend-endpoint { fill: var(--blue); stroke: #fff; stroke-width: 2; }
.chart-gridline { stroke: var(--border); stroke-width: 1; }
.trend-crosshair { stroke: var(--ink-dimmer); stroke-width: 1; stroke-dasharray: 3 3; }
.trend-hoverdot { fill: var(--blue); stroke: #fff; stroke-width: 2; }
.chart-axis-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-dimmer); margin-top: 6px; }

.chart-tooltip {
  position: absolute;
  transform: translate(-50%, -130%);
  background: rgba(11, 41, 66, 0.92);
  color: #fff;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 5;
}
.chart-tooltip strong { font-size: 10.5px; font-weight: 600; opacity: 0.8; }
.chart-tooltip span { font-size: 13px; font-weight: 700; }
.chart-tooltip.align-right { transform: translate(-90%, -130%); }

.stock-bar { display: flex; height: 28px; border-radius: 999px; overflow: hidden; background: rgba(var(--tint),0.06); gap: 2px; }
.stock-bar-seg { height: 100%; transition: width 0.5s ease; }
.stock-seg-instock { background: var(--amber); }
.stock-seg-sold { background: var(--green); }
.stock-legend { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; font-size: 13px; color: var(--ink); }
.stock-legend-item { display: flex; align-items: center; gap: 8px; }
.stock-legend-item strong { font-variant-numeric: tabular-nums; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend-dot.instock { background: var(--amber); }
.legend-dot.sold { background: var(--green); }

/* ===== Wallet panel ===== */
.wallet-panel {
  padding: 22px 24px;
  margin-bottom: 26px;
  animation: fade-in-up 0.5s ease both;
  animation-delay: 0.2s;
}
.wallet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}
.wallet-head h2 { margin: 0; font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.wallet-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-dim); }

.wallet-balances {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 8px;
  margin-bottom: 4px;
}
.wallet-tile {
  flex: 1 1 150px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  border: 1px solid var(--border);
}
.wallet-tile-icon { font-size: 24px; }
.wallet-tile-label { font-size: 12px; color: var(--ink-dim); display: block; }
.wallet-tile-value { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--green); }
.wallet-tile-value.negative { color: var(--red); }
.wallet-tile-value.neutral { color: var(--ink); }
.wallet-tile-sub { display: block; margin-top: 2px; font-size: 11.5px; color: var(--ink-dim); }

.logout-btn { display: inline-flex; align-items: center; gap: 8px; flex: 0 0 auto; }

/* ===== หน้าโปรไฟล์ ===== */
.profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.profile-avatar {
  width: 56px; height: 56px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--grad);
  color: #fff;
  font-size: 24px; font-weight: 800;
  box-shadow: 0 8px 20px rgba(var(--tint),0.32);
}
/* ชื่อร้านยาวแค่ไหนก็ต้องอยู่บรรทัดเดียวและไม่ดันปุ่มดินสอตก
   แทนที่จะวัดความกว้างด้วย JS แล้วค่อยย่อ (ซึ่งทำให้ layout กระตุกหนึ่งเฟรม)
   ฝั่ง JS ส่งมาแค่ "จำนวนตัวอักษร" แล้วให้ CSS คำนวณขนาดเอง (เทคนิคจาก ksmbxll) */
.profile-id { min-width: 0; }
.profile-id h2 {
  margin: 0;
  font-weight: 800;
  color: var(--ink);
  /* ที่ว่างจริง = ความกว้างจอ − รูปวงกลม 56 − ปุ่มดินสอ − ช่องไฟ − ขอบการ์ด */
  --name-box: min(calc(100vw - 190px), 620px);
  --name-fit: calc(var(--name-box) * 1.32 / max(8, var(--name-chars, 8)));
  font-size: max(13px, min(20px, var(--name-fit)));
  line-height: 1.35;
  /* สูตรข้างบนเป็นการ "ประเมิน" ความกว้าง สระบน–ล่างของไทยนับเป็นตัวอักษรแต่ไม่กินที่
     เลยกันพลาดไว้อีกชั้นด้วย ellipsis เผื่อชื่อที่ประเมินแล้วยังยาวเกิน */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-id p {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--ink-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.profile-stat {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.55);
  border: 1px solid var(--border);
}
.profile-stat-icon { grid-row: span 2; display: grid; place-items: center; }
.profile-stat-label { font-size: 11.5px; color: var(--ink-dim); }
.profile-stat-value { font-size: 16px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.profile-form { display: grid; gap: 14px; }

.wallet-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-block-sm { width: 100%; justify-content: center; font-size: 13px; padding: 10px 14px; }
.wallet-actions a.btn { text-decoration: none; }
.backup-panel { margin-top: 18px; }

/* ===== แถวสถิติแบบมีแถบเทียบ (เวลาขายออก / ลงทุนหมวดไหนคุ้ม) ===== */
.stat-rows { display: grid; gap: 8px; }
.stat-row {
  display: grid;
  grid-template-columns: minmax(96px, 1.2fr) minmax(60px, 2fr) auto;
  gap: 12px;
  align-items: center;
  font-size: 13px;
}
.stat-row-label { min-width: 0; color: var(--ink); font-weight: 600; }
.stat-row-label small { display: block; font-size: 11px; font-weight: 400; color: var(--ink-dimmer); line-height: 1.4; }
.stat-row-bar { height: 8px; background: var(--surface-soft); border-radius: 0 4px 4px 0; overflow: hidden; }
.stat-row-bar i { display: block; height: 100%; background: var(--grad); border-radius: 0 4px 4px 0; }
.stat-row-bar i.negative { background: var(--red); }
.stat-row-value { font-variant-numeric: tabular-nums; color: var(--ink-dim); white-space: nowrap; font-weight: 600; }
@media (max-width: 480px) {
  .stat-row { grid-template-columns: 1fr auto; }
  .stat-row-bar { grid-column: 1 / -1; }
}

/* ===== ราคาที่รุ่นเดียวกันเคยขายได้ ===== */
.price-hint {
  grid-column: 1 / -1;
  margin: -6px 0 0;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-dim);
  background: var(--surface-soft);
  border-left: 2px solid var(--border);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 8px 12px;
}
.price-hint b { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }
.price-hint small { color: var(--ink-dimmer); }

/* ===== แท็กที่ระบบเดาให้จากชื่อสินค้า ===== */
.tag-hints { gap: 7px; display: grid; }
.tag-hint-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.tag-hint {
  font: inherit;
  font-size: 13px;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px dashed var(--border);
  background: var(--surface-soft);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, transform 0.12s;
}
.tag-hint:hover { background: var(--surface); border-color: var(--ink-dim); border-style: solid; }
.tag-hint:active { transform: translateY(1px); }
.tag-hint small { font-size: 11px; color: var(--ink-dimmer); }

/* ===== ผลตรวจสุขภาพระบบ ===== */
.health-result { margin-top: 14px; }
.health-line { margin: 0 0 10px; font-size: 13.5px; font-weight: 600; }
.health-line.good { color: var(--green); }
.health-line.bad { color: var(--red); }
.health-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.health-list li {
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr auto;
  gap: 10px;
  align-items: baseline;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  font-size: 13px;
}
.health-list li::before {
  content: '';
  grid-row: 1;
  width: 7px; height: 7px;
  border-radius: 50%;
  align-self: center;
  margin-right: -4px;
}
.health-list li { grid-template-columns: 7px minmax(100px, auto) 1fr auto; }
.health-list li.ok::before { background: var(--green); }
.health-list li.bad::before { background: var(--red); }
.health-name { font-weight: 600; color: var(--ink); }
.health-detail { color: var(--ink-dim); min-width: 0; }
.health-list li.bad .health-detail { color: var(--red); }
.health-ms { color: var(--ink-dimmer); font-variant-numeric: tabular-nums; font-size: 12px; white-space: nowrap; }
.health-foot { margin: 10px 0 0; font-size: 12px; color: var(--ink-dimmer); }
@media (max-width: 480px) {
  .health-list li { grid-template-columns: 7px 1fr auto; }
  .health-detail { grid-column: 2 / -1; }
}

.wallet-history {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px dashed var(--border);
}
.wallet-history h3 { margin: 0 0 10px; font-size: 13.5px; color: var(--ink-dim); font-weight: 600; }
/* ไม่จำกัดความสูงแล้ว — ให้เลื่อนทั้งหน้าแทนการเลื่อนในกล่องเล็กๆ
   รายการจะโชว์ทีละชุด แล้วกดปุ่ม "ดูทั้งหมด" เพื่อกางส่วนที่เหลือ */
.wallet-tx-list { display: flex; flex-direction: column; gap: 8px; }
.wallet-tx-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  font-size: 13px;
  animation: fade-in-up 0.3s ease both;
}
.tx-type-badge { padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.tx-type-badge.withdraw { background: rgba(245, 158, 11, 0.22); color: #7c4a03; }
.tx-type-badge.reinvest { background: rgba(var(--tint-2), 0.22); color: #075566; }
.tx-type-badge.sale { background: rgba(22, 163, 74, 0.2); color: #0f5c30; }
.wallet-tx-amount.positive { color: var(--green); }
.wallet-tx-amount.negative { color: var(--ink); }
.wallet-tx-info { flex: 1; min-width: 0; }
.wallet-tx-note { color: var(--ink-dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wallet-tx-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.wallet-tx-meta { font-size: 11px; color: var(--ink-dimmer); white-space: nowrap; }
.wallet-empty { font-size: 13px; color: var(--ink-dimmer); text-align: center; padding: 14px 0; }

.wallet-hint {
  background: rgba(var(--tint), 0.07);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 12.5px;
  color: var(--ink-dim);
  margin-bottom: 18px;
  line-height: 1.6;
}
.wallet-hint strong { color: var(--ink); }

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  margin-bottom: 26px;
  flex-wrap: wrap;
}
.search-box {
  /* ห้ามใช้ flex-basis เป็น px ที่นี่ เพราะพอ .toolbar สลับเป็น flex-direction: column
     บนจอแคบ ค่านั้นจะถูกตีความเป็น "ความสูง" ทำให้ช่องค้นหาสูง 220px เต็มจอ
     ใช้ min-width แทน ได้ผลเหมือนกันในแนวนอนและปลอดภัยในแนวตั้ง */
  flex: 1 1 auto;
  min-width: min(220px, 100%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}
.search-box input {
  border: none; background: transparent; outline: none;
  color: var(--ink); font-family: inherit; font-size: 14px; width: 100%;
}
.search-icon { opacity: 0.7; }

.filter-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.5);
  color: var(--ink-dim);
  padding: 9px 16px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}
.chip:hover { color: var(--ink); border-color: rgba(var(--tint),0.35); }
.chip.active {
  background: var(--grad);
  color: white;
  border-color: transparent;
}

.view-toggle {
  display: flex; gap: 4px;
  background: rgba(255,255,255,0.5);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}
.view-toggle-btn {
  width: 34px; height: 34px;
  border: none; background: transparent;
  border-radius: 999px;
  cursor: pointer;
  font-size: 16px;
  color: var(--ink-dim);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s ease;
}
.view-toggle-btn:hover { color: var(--ink); }
.view-toggle-btn.active { background: var(--grad); color: #fff; }

/* ===== Bulk select ===== */
.select-checkbox {
  position: absolute;
  top: 12px; left: 12px;
  width: 26px; height: 26px;
  padding: 0;
  margin: 0;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.8);
  background: rgba(11,41,66,0.35);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-family: inherit;
  font-size: 15px;
  line-height: 1;
  color: transparent;
  transition: all 0.15s ease;
  z-index: 2;
}
.select-checkbox.checked {
  background: var(--grad);
  border-color: transparent;
  color: #fff;
}

.bulk-action-bar {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(20px) saturate(160%); -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 12px 10px 20px;
  box-shadow: var(--shadow-lift);
  animation: pop-in 0.25s cubic-bezier(.34,1.56,.64,1);
}
.bulk-action-bar span { font-size: 13.5px; font-weight: 600; color: var(--ink); white-space: nowrap; }
.bulk-action-buttons { display: flex; gap: 8px; }

/* ===== Product grid ===== */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}
.product-grid.list-mode {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.product-grid.selection-mode .card-actions,
.product-grid.selection-mode .card-footer,
.product-grid.selection-mode .list-actions {
  display: none;
}

.product-card {
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s cubic-bezier(.22,1,.36,1), box-shadow 0.3s ease;
  animation: pop-in 0.45s cubic-bezier(.34, 1.56, .64, 1) both;
}
.product-card:hover {
  transform: translateY(-8px);
  box-shadow: var(--shadow-lift);
}

.card-media {
  position: relative;
  aspect-ratio: 4 / 3;
  background: linear-gradient(135deg, rgba(var(--tint),0.18), rgba(var(--tint-2),0.12));
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.card-media img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform 0.4s ease;
}
.product-card:hover .card-media img { transform: scale(1.06); }
.card-media .placeholder-emoji { font-size: 46px; filter: drop-shadow(0 6px 14px rgba(var(--tint),0.25)); }

.status-badge {
  position: absolute;
  top: 12px; right: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.status-badge.in_stock { background: rgba(245, 158, 11, 0.9); color: #402c00; }
.status-badge.sold { background: rgba(22, 163, 74, 0.9); color: #ffffff; }

.card-actions {
  position: absolute;
  top: 12px; left: 12px;
  display: flex; gap: 6px;
  opacity: 0;
  transform: translateY(-6px);
  transition: all 0.2s ease;
}
.product-card:hover .card-actions, .product-card:focus-within .card-actions { opacity: 1; transform: translateY(0); }
.card-actions .icon-btn { background: rgba(11, 41, 66, 0.5); color: #fff; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.card-actions .icon-btn:hover { background: rgba(11, 41, 66, 0.7); }

/* อุปกรณ์ที่ไม่มี hover (มือถือ/แท็บเล็ต) ให้ปุ่มแสดงตลอดเวลา แตะได้ทันที */
@media (hover: none) {
  .card-actions { opacity: 1; transform: translateY(0); }
  .icon-btn { width: 40px; height: 40px; font-size: 16px; }
}

.card-footer {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.mark-sold-btn {
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.mark-sold-btn.to-sold {
  background: linear-gradient(135deg, rgba(22,163,74,0.16), rgba(22,163,74,0.08));
  color: #0f5c30;
}
.mark-sold-btn.to-sold:hover { background: linear-gradient(135deg, rgba(22,163,74,0.26), rgba(22,163,74,0.14)); transform: translateY(-1px); }
.mark-sold-btn.to-stock {
  background: rgba(var(--tint), 0.08);
  color: var(--ink-dim);
}
.mark-sold-btn.to-stock:hover { background: rgba(var(--tint), 0.14); transform: translateY(-1px); }

.card-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.card-title { font-size: 16px; font-weight: 700; margin: 0; line-height: 1.35; color: var(--ink); }
.card-desc {
  color: var(--ink-dim); font-size: 12.5px; margin: -4px 0 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.price-rows { display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.price-row { display: flex; justify-content: space-between; color: var(--ink-dim); }
.price-row span:last-child { color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }

.profit-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.profit-line span:first-child { font-size: 12.5px; color: var(--ink-dim); }
.profit-value { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.profit-value.positive { color: var(--green); }
.profit-value.negative { color: var(--red); }
.profit-pending { font-size: 17px; font-weight: 800; color: var(--ink-dimmer); }

/* ===== Product list (มุมมองรายการ) ===== */
.product-list-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-soft);
  animation: fade-in-up 0.4s ease both;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.product-list-item:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }

.list-thumb {
  position: relative;
  width: 64px; height: 64px;
  border-radius: 14px;
  overflow: hidden;
  flex-shrink: 0;
  background: linear-gradient(135deg, rgba(var(--tint),0.18), rgba(var(--tint-2),0.12));
  display: flex; align-items: center; justify-content: center;
}
.list-thumb img { width: 100%; height: 100%; object-fit: cover; }
.list-thumb .placeholder-emoji { font-size: 24px; }

.list-info { flex: 1; min-width: 0; }
.list-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-title { font-size: 15px; font-weight: 700; margin: 0; color: var(--ink); }
.status-badge.inline { position: static; display: inline-flex; align-items: center; }
.list-desc {
  font-size: 12px; color: var(--ink-dim); margin: 2px 0 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-meta { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-dim); margin-top: 6px; }

.list-profit { display: flex; flex-direction: column; align-items: flex-end; flex-shrink: 0; min-width: 90px; }
.list-profit-label { font-size: 11px; color: var(--ink-dim); }
.list-actions { display: flex; gap: 6px; flex-shrink: 0; }

@media (max-width: 640px) {
  .product-list-item { flex-wrap: wrap; }
  .list-info { flex: 1 1 100%; order: 2; }
  .list-thumb { order: 1; }
  .list-profit { order: 3; flex: 1; align-items: flex-start; }
  .list-actions { order: 4; }
}

/* ===== Empty state & skeleton ===== */
.empty-state {
  text-align: center;
  padding: 70px 20px;
  animation: fade-in 0.5s ease;
}
.empty-emoji { font-size: 56px; margin-bottom: 12px; animation: bob 3.5s ease-in-out infinite; }
.empty-state h3 { margin: 0 0 6px; font-size: 18px; color: var(--ink); }
.empty-state p { color: var(--ink-dim); margin: 0 0 20px; font-size: 14px; }

.skel-card {
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
}
.skel-card::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(var(--tint),0.12), transparent);
  animation: shimmer 1.6s infinite;
}
@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(11, 41, 66, 0.28);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  /* ต้องสูงกว่าเมนูล่างมือถือ (60) และแถบเลือกขายหลายชิ้น (70)
     ไม่งั้นสองอันนั้นจะลอยทับปุ่มยืนยันด้านล่างของ modal จนกดไม่ได้ */
  z-index: 80;
  animation: fade-in 0.2s ease;
}
.modal {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 26px 28px 28px;
  animation: pop-in 0.3s cubic-bezier(.34,1.56,.64,1);
  background: rgba(255,255,255,0.85);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.modal-head h2 { margin: 0; font-size: 19px; font-weight: 700; color: var(--ink); }

.dropzone {
  position: relative;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  min-height: 160px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 20px;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.2s ease, background 0.2s ease;
  background: rgba(var(--tint),0.04);
}
.dropzone:hover, .dropzone.drag-over { border-color: var(--teal); background: rgba(var(--tint-2),0.08); }
.dropzone-hint { text-align: center; color: var(--ink-dim); font-size: 13.5px; padding: 20px; }
.dropzone-emoji { font-size: 30px; display: block; margin-bottom: 6px; }
.link-text { color: var(--blue); font-weight: 600; }
.image-preview { width: 100%; height: 220px; object-fit: cover; display: block; }
.remove-image-btn {
  position: absolute; top: 10px; right: 10px;
  background: rgba(11,41,66,0.55);
  color: #fff;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 14px;
}

.cost-items-field { margin-top: 4px; margin-bottom: 8px; }
.cost-items-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.cost-item-row { display: flex; gap: 8px; align-items: center; }
/* มีต้นทุนก้อนเดียวก็ไม่ต้องให้ตั้งชื่อ เหลือแค่ช่องจำนวนเงินให้กรอก
   กดเพิ่มรายการที่สองเมื่อไหร่ ชื่อถึงจะมีความหมาย ค่อยโผล่ขึ้นมาทุกแถว */
.single-cost .cost-item-name { display: none; }
.single-cost .cost-item-row input[type="number"] { flex: 1 1 auto; width: auto; }
.cost-item-row input[type="text"] {
  flex: 1 1 auto; min-width: 0;
  background: rgba(255,255,255,0.65); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 11px 12px; color: var(--ink); font-family: inherit; font-size: 14px; outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.cost-item-row input[type="number"] {
  width: 108px; flex-shrink: 0;
  background: rgba(255,255,255,0.65); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 11px 12px; color: var(--ink); font-family: inherit; font-size: 14px; outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.cost-item-row input:focus { border-color: var(--blue); background: rgba(var(--tint),0.06); }
.cost-item-row .remove-cost-item-btn { flex-shrink: 0; }
.btn-sm { padding: 9px 16px; font-size: 13px; }
.cost-items-total {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-radius: var(--radius-sm);
  background: rgba(var(--tint),0.06); border: 1px solid var(--border);
  font-size: 13px; color: var(--ink-dim); margin-top: 10px;
}
.cost-items-total strong { font-size: 16px; color: var(--ink); font-variant-numeric: tabular-nums; }

.status-field { margin-top: 4px; }
.status-label { display: block; font-size: 12.5px; color: var(--ink-dim); margin-bottom: 8px; }
.status-toggle { display: flex; gap: 10px; }
.status-opt {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.5);
  color: var(--ink-dim);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.status-opt.active {
  background: var(--grad);
  color: white;
  border-color: transparent;
}

.profit-preview {
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(var(--tint),0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 16px 0 22px;
  font-size: 13.5px;
  color: var(--ink-dim);
}
.profit-preview strong { font-size: 18px; color: var(--green); font-variant-numeric: tabular-nums; }
.profit-preview strong.negative { color: var(--red); }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.confirm-modal { max-width: 360px; text-align: center; padding: 32px 28px; }
.confirm-emoji { font-size: 42px; margin-bottom: 10px; }
.confirm-modal h3 { margin: 0 0 6px; color: var(--ink); }
.confirm-modal p { color: var(--ink-dim); font-size: 13.5px; margin: 0 0 22px; }
.confirm-modal .modal-actions { justify-content: center; }

.sold-modal { max-width: 480px; }
.sold-items-list { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; max-height: 320px; overflow-y: auto; }
.sold-item-row {
  display: flex; align-items: center; gap: 12px;
  background: rgba(var(--tint),0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.sold-item-info { flex: 1; min-width: 0; }
.sold-item-name { display: block; font-size: 14px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sold-item-meta { display: block; font-size: 11.5px; color: var(--ink-dim); margin-top: 2px; }
.sold-item-price { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.sold-item-price-input {
  width: 100px; text-align: right;
  background: rgba(255,255,255,0.7); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px; color: var(--ink); font-family: inherit; font-size: 13.5px; outline: none;
  transition: border-color 0.2s ease;
}
.sold-item-price-input:focus { border-color: var(--blue); }
.sold-item-profit { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sold-item-profit.positive { color: var(--green); }
.sold-item-profit.negative { color: var(--red); }

.sold-summary {
  display: flex; flex-direction: column; gap: 8px;
  background: rgba(var(--tint),0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-top: 4px;
  font-size: 13.5px;
}
.sold-summary-row { display: flex; justify-content: space-between; align-items: center; color: var(--ink-dim); }
.sold-summary-row strong { font-size: 15px; color: var(--ink); font-variant-numeric: tabular-nums; }

.sold-channel-row { display: grid; grid-template-columns: 1.5fr 1fr; gap: 12px; }
.channel-select {
  width: 100%;
  background: rgba(255,255,255,0.65);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px 12px 8px;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  /* ลูกศรวาดเอง เพราะปิด appearance ของ Safari ไปแล้ว */
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-dim) 50%), linear-gradient(135deg, var(--ink-dim) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.channel-select:focus { border-color: var(--blue); }
.field .static-label { top: 5px; font-size: 11px; color: var(--teal); }

.margin-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(var(--tint),0.12);
  color: var(--blue);
  margin-left: 4px;
}
.margin-badge.good { background: rgba(22,163,74,0.16); color: #0f5c30; }
.margin-badge.thin { background: rgba(245,158,11,0.2); color: #7c4a03; }
.margin-badge.loss { background: rgba(225,29,72,0.16); color: #9f1239; }

.card-margin { font-size: 11.5px; font-weight: 700; }

/* แถบแสดงสัดส่วนที่ขายไปแล้วของล็อต */
.lot-bar {
  height: 6px; border-radius: 999px; overflow: hidden;
  background: rgba(var(--tint), 0.12); margin-top: 2px;
}
.lot-bar span { display: block; height: 100%; background: var(--grad); transition: width 0.4s ease; }

.field-hint { font-size: 11.5px; color: var(--ink-dim); margin: 8px 0 0; min-height: 1em; }

/* ปุ่มเรียกเครื่องคิดราคา — เต็มความกว้างและมีข้อความ ไม่ใช่ไอคอนเล็กๆ
   ที่ไปทับลูกศรขึ้นลงของช่องตัวเลขจนมองไม่เห็น */
.calc-cta-wrap { margin: -8px 0 18px; }
.calc-cta {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  padding: 13px 16px;
  border: 1.5px dashed var(--blue);
  border-radius: var(--radius-sm);
  background: rgba(var(--tint), 0.07);
  color: var(--blue);
  font-family: inherit; font-size: 13.5px; font-weight: 600;
  cursor: pointer; text-align: left;
  transition: background 0.2s ease, transform 0.15s ease;
}
.calc-cta:hover { background: rgba(var(--tint), 0.14); }
.calc-cta:active { transform: scale(0.99); }
.calc-cta .ic { width: 22px; height: 22px; flex-shrink: 0; }

@media (max-width: 480px) {
  .calc-cta { font-size: 12.5px; padding: 12px 12px; }
}

.calc-mode-toggle .status-opt { padding: 10px 6px; font-size: 12.5px; }

.calc-result {
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: rgba(var(--tint), 0.05); padding: 16px 18px; margin: 6px 0 20px;
}
.calc-price { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.calc-price-label { font-size: 13px; color: var(--ink-dim); }
.calc-price-value {
  font-size: 28px; font-weight: 800; color: var(--blue);
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
}
.calc-lines {
  display: flex; flex-direction: column; gap: 5px;
  margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border);
  font-size: 13px;
}
.calc-line { display: flex; justify-content: space-between; gap: 10px; color: var(--ink-dim); }
.calc-line span:last-child { font-variant-numeric: tabular-nums; color: var(--ink); }
.calc-line.neg span:last-child { color: var(--ink-dim); }
.calc-line.total {
  margin-top: 4px; padding-top: 8px; border-top: 1px solid var(--border);
  font-weight: 700; color: var(--ink);
}
.calc-line.total .positive { color: var(--green); }
.calc-line.total .negative { color: var(--red); }
.calc-breakeven { font-size: 11.5px; color: var(--ink-dim); margin: 12px 0 0; }
.calc-error { font-size: 13px; color: var(--red); margin: 0; }

/* ช่องจำนวน + ราคา ในหน้าบันทึกการขาย */
.sold-item-fields { display: flex; gap: 8px; }
.mini-field { display: flex; flex-direction: column; gap: 3px; }
.mini-field span { font-size: 10.5px; color: var(--ink-dim); }
.mini-field input {
  width: 84px; text-align: right;
  background: rgba(255,255,255,0.7); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px; color: var(--ink); font-family: inherit; font-size: 13.5px; outline: none;
  -webkit-appearance: none; appearance: none;
}
.mini-field input:focus { border-color: var(--blue); }
.sold-item-qty-input { width: 66px !important; }

/* ประวัติการขายของสินค้าชิ้นหนึ่ง */
.history-list { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; max-height: 300px; overflow-y: auto; }
.history-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-soft); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 14px;
}
.history-info { flex: 1; min-width: 0; }
.history-main { font-size: 14px; font-weight: 600; color: var(--ink); }
.history-meta { font-size: 11.5px; color: var(--ink-dim); margin-top: 2px; }
.history-profit { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.history-profit.positive { color: var(--green); }
.history-profit.negative { color: var(--red); }

@media (max-width: 480px) {
  .sold-item-fields { width: 100%; }
  .mini-field { flex: 1; }
  .mini-field input, .sold-item-qty-input { width: 100% !important; }
}

.transfer-from {
  background: rgba(var(--tint),0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 18px;
}
.transfer-from-label { display: block; font-size: 11.5px; color: var(--ink-dim); }
.transfer-from strong { display: block; font-size: 15px; color: var(--ink); margin-top: 2px; }
.transfer-from-cost { display: block; font-size: 12px; color: var(--ink-dim); margin-top: 2px; font-variant-numeric: tabular-nums; }
.transfer-over { color: var(--red); }
.transfer-warn span { color: var(--red); font-size: 12px; }
@media (max-width: 480px) {
  .sold-channel-row { grid-template-columns: 1fr; }
}

/* ===== Toasts ===== */
.toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 100;
}
.toast {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lift);
  font-size: 13.5px;
  color: var(--ink);
  display: flex; align-items: center; gap: 10px;
  min-width: 240px;
  animation: slide-in 0.3s cubic-bezier(.34,1.56,.64,1);
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.leaving { animation: slide-out 0.25s ease forwards; }

/* ===== Keyframes ===== */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.9) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes slide-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes slide-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ===== iOS Safari ===== */
/* ช่องกรอกที่ฟอนต์เล็กกว่า 16px จะทำให้ iPhone ซูมจอเข้าเองตอนแตะ แล้วไม่ซูมกลับ
   บังคับ 16px เฉพาะอุปกรณ์สัมผัส เพื่อไม่ให้ดีไซน์บนคอมเปลี่ยน */
@media (hover: none) and (pointer: coarse) {
  /* iOS ซูมจอเข้าเองทุกครั้งที่แตะช่องที่ฟอนต์เล็กกว่า 16px แล้วไม่ซูมกลับ
     ต้องใช้ !important เพราะกฎรายคอมโพเนนต์อย่าง .field input มี specificity สูงกว่า
     ตัวเลือกระดับ element เสมอ — เคยเขียนเป็นรายชื่อคลาสแล้ว แต่พอเพิ่มฟอร์มใหม่ก็หลุดทุกที */
  input, select, textarea {
    font-size: 16px !important;
  }
  .field label { font-size: 16px; }
  .field input:focus + label,
  .field input:not(:placeholder-shown) + label,
  .field textarea:focus + label,
  .field textarea:not(:placeholder-shown) + label {
    font-size: 11px;
  }
  .sold-item-price-input { width: 116px; }
}

input, textarea {
  /* Safari ใส่เงาในและสไตล์ของตัวเองให้ช่องกรอก ทำให้หน้าตาเพี้ยนจากที่ออกแบบไว้ */
  -webkit-appearance: none;
  appearance: none;
}

body {
  /* กันตัวอักษรถูกขยายเองตอนหมุนจอ และกันไฮไลต์สีฟ้าตอนแตะปุ่ม */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  /* แตะปุ่มรัวๆ บน iPhone จะถูกนับเป็น double-tap แล้วจอซูมค้าง
     manipulation ตัดเฉพาะ double-tap zoom การซูมด้วยสองนิ้วยังทำได้ตามปกติ */
  touch-action: manipulation;
}


/* ===== แถบรูปสินค้าในฟอร์ม ===== */
.image-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 10px 0 4px;
}
.image-strip:empty { margin: 0; }
.image-cell {
  position: relative;
  width: 92px;
  height: 92px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.6);
}
.image-cell.is-cover { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(var(--tint),0.18); }
.image-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-cell .image-remove-btn {
  position: absolute;
  top: 4px; right: 4px;
  width: 26px; height: 26px;
  background: rgba(255,255,255,0.9);
}
.image-cell .image-cover-btn {
  position: absolute;
  left: 4px; right: 4px; bottom: 4px;
  padding: 4px 0;
  font-size: 11px;
  background: rgba(255,255,255,0.92);
}
.cover-badge {
  position: absolute;
  left: 4px; top: 4px;
  background: var(--grad);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}
.image-strip-hint { margin: 0 0 14px; font-size: 12px; color: var(--ink-dim); }

.photo-count {
  position: absolute;
  left: 10px; bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(15,23,42,0.55);
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
}
.card-media img, .list-thumb img { cursor: zoom-in; }

/* ===== แท็ก ===== */
.tag-row { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 6px; }
.tag-chip {
  font-size: 11px;
  font-weight: 600;
  color: var(--blue);
  background: rgba(var(--tint),0.1);
  border-radius: 999px;
  padding: 2px 9px;
}

.toolbar-selects { display: flex; gap: 8px; flex: 0 1 auto; }
.toolbar-select {
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  background: rgba(255,255,255,0.65);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 12px;
  max-width: 170px;
}

/* ===== ตารางสรุปรายเดือน ===== */
.table-scroll { overflow-x: auto; }
.month-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}
.month-table th, .month-table td {
  padding: 9px 10px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.month-table th:first-child, .month-table td:first-child { text-align: left; }
.month-table th { font-size: 11.5px; color: var(--ink-dim); font-weight: 600; }
.month-table tbody tr:last-child td { border-bottom: none; }
.month-table td.positive { color: var(--green); font-weight: 700; }
.month-table td.negative { color: var(--red); font-weight: 700; }
.month-table .chart-empty { text-align: center; }

/* ===== ของค้างสต็อกนาน ===== */
.dead-stock-list { display: flex; flex-direction: column; gap: 8px; }
.dead-stock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.55);
  border: 1px solid var(--border);
}
.dead-stock-info { display: flex; flex-direction: column; min-width: 0; }
.dead-stock-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dead-stock-meta { font-size: 12px; color: var(--ink-dim); }
.dead-stock-days {
  flex: 0 0 auto;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--orange, #ea580c);
  background: rgba(234,88,12,0.12);
  border-radius: 999px;
  padding: 4px 10px;
}

/* ===== ไลท์บ็อกซ์ดูรูป ===== */
.lightbox-overlay { background: rgba(8,15,30,0.82); }
.lightbox {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: min(92vw, 900px);
}
.lightbox img {
  max-width: 100%;
  max-height: 72vh;
  border-radius: var(--radius-md);
  background: #0b1220;
}
.lightbox-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  color: #fff;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.lightbox-bar .btn { min-width: 44px; font-size: 20px; line-height: 1; padding: 6px 14px; }
.lightbox-close {
  position: absolute;
  top: -46px;
  right: 0;
  background: rgba(255,255,255,0.9);
}



.stat-sub { display: block; margin-top: 3px; font-size: 11.5px; color: var(--ink-dim); }
.stat-icon-capital { background: rgba(var(--tint-2),0.14); }

/* ===== ยอดรวมของร้าน + สมการที่มาของเงิน ===== */
.total-tile {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 13px 16px;
  margin-bottom: 10px;
  border-radius: var(--radius-md);
  background: var(--grad);
  color: #fff;
  box-shadow: 0 10px 26px rgba(var(--tint),0.28);
}
.total-tile-label { font-size: 12.5px; opacity: 0.92; }
.total-tile-value { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.25; }
.total-tile-value.negative { color: #ffe4e6; }
.total-tile-sub { font-size: 12.5px; opacity: 0.9; }

.balance-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  margin: 14px 0 4px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.5);
  border: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--ink-dim);
}
.balance-part { white-space: nowrap; }
.balance-part b {
  display: block;
  font-size: 14.5px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.balance-op { font-size: 16px; font-weight: 700; color: var(--ink-dimmer); }


/* ===== ปุ่มพับ/กางรายละเอียด ===== */
.disclosure-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 10px 0 0;
  padding: 6px 12px 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255,255,255,0.5);
  color: var(--ink-dim);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.disclosure-btn:hover { color: var(--ink); }
.disclosure-chevron { transition: transform 0.2s ease; }
.disclosure-btn.open .disclosure-chevron { transform: rotate(180deg); }

.history-count {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-dimmer);
}

/* ===== รายการข้อมูลแบบอ่านอย่างเดียว (หน้าโปรไฟล์) ===== */
.info-list { margin: 0 0 16px; display: flex; flex-direction: column; }
.info-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--border);
}
.info-row:last-child { border-bottom: none; }
.info-row dt { font-size: 13px; color: var(--ink-dim); flex: 0 0 auto; }
.info-row dd {
  margin: 0;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--ink);
  text-align: right;
  word-break: break-word;
}
.info-row dd.empty { font-weight: 500; color: var(--ink-dimmer); }

.profile-head { position: relative; }
.profile-head .icon-btn { margin-left: auto; flex: 0 0 auto; }


/* ===== ธีมสี =====
   ธีม A (ค่าเริ่มต้น) อยู่ใน :root ข้างบน ส่วนอีกสองธีมแค่เขียนทับ "ตัวแปรสี" เท่านั้น
   ไม่มีคอมโพเนนต์ไหนฮาร์ดโค้ดสีเอง การสลับธีมจึงเปลี่ยนทั้งแอปได้ในบรรทัดเดียว
   โทนที่สองอิงจาก kosame.online (ฟ้าเทา–ครีม) โทนที่สามอิงจาก ksmbxll.com (ชมพูพาสเทล) */

[data-theme="kosame"] {
  --tint: 108, 138, 156;
  --tint-2: 141, 174, 190;
  --bg-1: #f5f1e8;
  --bg-2: #e9e2d5;
  --bg-3: #d5dfe4;
  --ink: #2c1f16;
  --ink-dim: #6b5b4c;
  --ink-dimmer: #9d8b79;
  --surface: rgba(255, 255, 255, 0.68);
  --surface-soft: rgba(255, 255, 255, 0.46);
  --border: rgba(108, 138, 156, 0.24);
  --sky: #b6c7d3;
  --blue: #6c8a9c;
  --teal: #8daebe;
  --indigo: #9d8b79;
  --green: #4f7a52;
  --red: #b4553f;
  --amber: #c4a882;
  --grad: linear-gradient(135deg, #6c8a9c, #9db9c7);
  --grad-warm: linear-gradient(135deg, #c4a882, #9d8b79);
  --shadow-soft: 0 8px 30px rgba(120, 160, 190, 0.18);
  --shadow-lift: 0 20px 45px rgba(120, 160, 190, 0.3);
}

[data-theme="peach"] {
  --tint: 181, 100, 127;
  --tint-2: 220, 170, 192;
  --bg-1: #fff7fb;
  --bg-2: #feeef5;
  --bg-3: #fbd3e2;
  --ink: #52323f;
  --ink-dim: #8c4f68;
  --ink-dimmer: #b98aa0;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-soft: rgba(255, 255, 255, 0.5);
  --border: rgba(140, 79, 104, 0.18);
  --sky: #fbd3e2;
  --blue: #b5647f;
  --teal: #dcaac0;
  --indigo: #a86b86;
  --green: #4f8a6a;
  --red: #d6455f;
  --amber: #dda15e;
  --grad: linear-gradient(135deg, #b5647f, #d79fb4);
  --grad-warm: linear-gradient(135deg, #dda15e, #dc8f7a);
  --shadow-soft: 0 8px 30px rgba(180, 110, 140, 0.16);
  --shadow-lift: 0 20px 45px rgba(180, 110, 140, 0.26);
}

/* ปุ่มเลือกธีมในหน้าโปรไฟล์ */
.theme-picker { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.theme-swatch {
  flex: 1 1 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 12px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-soft);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-dim);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.theme-swatch:hover { transform: translateY(-2px); }
.theme-swatch.active {
  border-color: var(--blue);
  color: var(--ink);
  box-shadow: 0 0 0 2px var(--border), var(--shadow-soft);
}
.theme-dots { display: flex; gap: 4px; }
.theme-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.75);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.6);
}

/* ===== แถบข่าววิ่งหน้าแรก (ยืมจาก kosame) ===== */
.ticker {
  position: relative;
  overflow: hidden;
  margin-bottom: 14px;
  padding: 9px 0;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.85);
}
.ticker-track {
  display: inline-block;
  white-space: nowrap;
  padding-left: 100%;
  animation: marquee 26s linear infinite;
  font-size: 13px;
  color: var(--ink-dim);
}
.ticker:hover .ticker-track { animation-play-state: paused; }
.ticker-item { padding: 0 10px; }
.ticker-item b { color: var(--ink); font-variant-numeric: tabular-nums; }
.ticker-sep { color: var(--ink-dimmer); }
@keyframes marquee {
  from { transform: translateX(0); }
  to { transform: translateX(-100%); }
}

/* ===== การ์ดเป้ากำไรรายเดือน (ยืมบัตรสะสมแต้มจาก ksmbxll) ===== */
.goal-card { margin-bottom: 18px; }
.goal-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.goal-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 7px; }
.goal-sub { font-size: 12.5px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.goal-stamps {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 7px;
}
.goal-stamp {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1.5px dashed var(--border);
  display: grid;
  place-items: center;
  color: var(--ink-dimmer);
  font-size: 11px;
  font-weight: 700;
  background: var(--surface-soft);

  /* ดวงที่ปั๊มแล้วถ้าเรียงตรงเป๊ะจะดูเป็น "ไอคอน" ไม่ใช่ "รอยปั๊ม"
     แจกมุมเอียง ระยะเยื้อง และความเข้มหมึกให้ต่างกันทีละดวงด้วย nth-child
     วนซ้ำทุก 10 ดวง — ทำด้วย CSS ล้วน ไม่ใช้ Math.random() ในการวาด
     เพราะจะได้หน้าตาไม่ซ้ำเดิมทุกครั้งที่การ์ดถูกวาดใหม่ (เทคนิคจาก ksmbxll)

     ระยะเยื้องเป็น % ไม่ใช่ px เพราะเปอร์เซ็นต์ใน translate() คิดจากขนาดตัวเอง
     ดวงกว้าง ~100px บนคอมกับ ~26px บนมือถือจึงเยื้องเป็นสัดส่วนเท่ากัน
     ไม่ต้องมี media query มาคอยย่อค่าให้ (ต้นฉบับใช้ px เพราะดวงเขาคุมขนาดไว้แล้ว) */
  --stamp-rot: -5deg;
  --stamp-x: 0%;
  --stamp-y: 0%;
  --stamp-ink: 1;
}
.goal-stamp:nth-child(10n + 1) { --stamp-rot: -9.5deg;  --stamp-x: -2.7%;  --stamp-y: 2%;     --stamp-ink: 0.93; }
.goal-stamp:nth-child(10n + 2) { --stamp-rot: 6.5deg;   --stamp-x: 2%;     --stamp-y: -2.7%;  --stamp-ink: 1; }
.goal-stamp:nth-child(10n + 3) { --stamp-rot: -4deg;    --stamp-x: 2.7%;   --stamp-y: 2.7%;   --stamp-ink: 0.88; }
.goal-stamp:nth-child(10n + 4) { --stamp-rot: 11deg;    --stamp-x: -2%;    --stamp-y: -1.35%; --stamp-ink: 0.97; }
.goal-stamp:nth-child(10n + 5) { --stamp-rot: -7deg;    --stamp-x: 1.35%;  --stamp-y: 2.7%;   --stamp-ink: 0.91; }
.goal-stamp:nth-child(10n + 6) { --stamp-rot: 3.5deg;   --stamp-x: -2.7%;  --stamp-y: -1.35%; --stamp-ink: 1; }
.goal-stamp:nth-child(10n + 7) { --stamp-rot: -11.5deg; --stamp-x: 2.7%;   --stamp-y: 1.35%;  --stamp-ink: 0.87; }
.goal-stamp:nth-child(10n + 8) { --stamp-rot: 8.5deg;   --stamp-x: -1.35%; --stamp-y: -2.7%;  --stamp-ink: 0.95; }
.goal-stamp:nth-child(10n + 9) { --stamp-rot: -5deg;    --stamp-x: -2.7%;  --stamp-y: 2.7%;   --stamp-ink: 0.9; }
.goal-stamp:nth-child(10n)     { --stamp-rot: 9.5deg;   --stamp-x: 2%;     --stamp-y: 2%;     --stamp-ink: 0.98; }

.goal-stamp.filled {
  border-style: solid;
  border-color: transparent;
  background: var(--grad);
  color: #fff;
  box-shadow: var(--shadow-soft), inset 0 1px rgba(255, 255, 255, 0.5);
  opacity: var(--stamp-ink);
  transform: translate(var(--stamp-x), var(--stamp-y)) rotate(var(--stamp-rot));
}
/* เล่นเฉพาะดวงที่เพิ่งได้มารอบนี้ ไม่ใช่ปั๊มใหม่ทั้งแถวทุกครั้งที่หน้าถูกวาดซ้ำ
   เฟรมสุดท้ายตรงกับ .filled ด้านบนพอดี พอถอดคลาสออกจึงไม่มีการกระตุก */
.goal-stamp.just-stamped { animation: stamp-drop 0.62s cubic-bezier(.2, .7, .3, 1) both; }
@keyframes stamp-drop {
  0% {
    opacity: 0;
    /* ระยะตกเป็น % ของตัวเอง ดวงใหญ่บนคอมจึงตกไกลกว่าดวงเล็กบนมือถือตามสัดส่วน */
    transform: translateY(-60%) rotate(-16deg) scale(1.35);
  }
  60% {
    opacity: var(--stamp-ink);
    transform: translate(var(--stamp-x), calc(var(--stamp-y) + 5.4%)) rotate(var(--stamp-rot)) scale(0.9);
  }
  80% {
    opacity: var(--stamp-ink);
    transform: translate(var(--stamp-x), calc(var(--stamp-y) - 2.7%)) rotate(var(--stamp-rot)) scale(1.06);
  }
  100% {
    opacity: var(--stamp-ink);
    transform: translate(var(--stamp-x), var(--stamp-y)) rotate(var(--stamp-rot)) scale(1);
  }
}
.goal-hint { margin: 12px 0 0; font-size: 12.5px; color: var(--ink-dim); }
.goal-hint.done { color: var(--green); font-weight: 600; }

/* ===== มาสคอตในหน้าว่าง ===== */
.mascot { width: 76px; height: 76px; animation: bob 3.5s ease-in-out infinite; }
.empty-note { font-size: 12.5px; color: var(--ink-dimmer); margin-top: -8px; }
.chart-empty .mascot, .wallet-empty .mascot { width: 54px; height: 54px; }
.empty-inline {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 28px 10px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-dimmer);
}


/* ===== ช่องแนบสลิปตอนบันทึกการขาย ===== */
.slip-box {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 78px;
  margin-bottom: 20px;
  padding: 12px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.slip-box:hover, .slip-box.drag-over { border-color: var(--blue); background: rgba(var(--tint), 0.06); }
.slip-hint { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-dim); }
.slip-preview { max-height: 190px; max-width: 100%; border-radius: var(--radius-sm); display: block; }
.slip-remove { position: absolute; top: 8px; right: 8px; background: rgba(255,255,255,0.92); }

/* สลิปย่อในประวัติการขาย */
.history-slip {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-soft);
  cursor: zoom-in;
}
.history-slip img { width: 100%; height: 100%; object-fit: cover; display: block; }


/* ===== หน้ารายละเอียดสินค้า ===== */
.detail-modal { max-width: 560px; }
.detail-heading h2 { margin: 0; font-size: 19px; }
.detail-heading p { margin: 3px 0 0; font-size: 12.5px; color: var(--ink-dim); }

.detail-shots { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; }
.detail-shot {
  flex: 0 0 auto;
  width: 96px;
  height: 96px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-soft);
  cursor: zoom-in;
}
.detail-shot img { width: 100%; height: 100%; object-fit: cover; display: block; }

.detail-desc { margin: 0 0 14px; font-size: 14px; color: var(--ink-dim); }

.detail-section { margin-bottom: 18px; }
.detail-section h4 {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-dimmer);
  letter-spacing: 0.04em;
}
.detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.detail-row:last-child { border-bottom: none; }
.detail-row > span { color: var(--ink-dim); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.detail-row strong { font-variant-numeric: tabular-nums; }
.detail-row strong.positive { color: var(--green); }
.detail-row strong.negative { color: var(--red); }
.detail-row.sale em { font-style: normal; font-size: 12px; color: var(--ink-dimmer); width: 100%; }
.detail-empty { margin: 0; font-size: 13px; color: var(--ink-dimmer); padding: 8px 0; }

.detail-slip {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-soft);
  cursor: zoom-in;
}
.detail-slip:hover { border-color: var(--blue); }

.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.detail-actions .btn { flex: 1 1 140px; justify-content: center; }

/* การ์ดกดได้ทั้งใบ */
.product-card, .product-list-item { cursor: pointer; }
.product-card button, .product-list-item button { cursor: pointer; }


/* ปุ่มรีเฟรชบนหัวเว็บ */
.refresh-btn { display: inline-flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.refresh-btn.spinning .ic { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }


/* ตอนแก้ไขโปรไฟล์ ซ่อนกล่องสำรองข้อมูล/ความปลอดภัยไว้ก่อน ให้เหลือแต่ฟอร์มที่กำลังกรอก */
body.editing-profile #pageProfile > .wallet-panel:not(:first-child) { display: none; }


/* แถวประวัติที่โยงกับสินค้าได้ กดแล้วเด้งไปดูของชิ้นนั้น */
.wallet-tx-row.linked { cursor: pointer; }
.wallet-tx-row.linked:hover { border-color: var(--blue); }

/* ===== จัดส่ง ===== */
/* ป็อปอัพยืนยันต้องอยู่เหนือป็อปอัพอื่นเสมอ (กดลบรายการจัดส่งจากในป็อปอัพแก้ไข) */
#confirmOverlay { z-index: 85; }

.order-list { display: grid; gap: 10px; }
.order-row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.55);
}
/* แถบสีด้านซ้ายบอกสถานะ ไล่สายตาดูแล้วรู้ทันทีว่าชิ้นไหนยังค้าง */
.order-row { border-left: 4px solid var(--order-tone, var(--border)); }
.order-row[data-status="preparing"] { --order-tone: #f59e0b; }
.order-row[data-status="shipped"] { --order-tone: var(--blue); }
.order-row[data-status="delivered"] { --order-tone: #16a34a; }
.order-row[data-status="cancelled"] { --order-tone: #e11d48; opacity: 0.8; }
.order-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.order-top { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.order-code { font-weight: 700; letter-spacing: 0.08em; font-variant-numeric: tabular-nums; }
.order-customer { font-weight: 500; color: var(--ink); }
.order-chip {
  font-size: 11px; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--ink-dim);
}
.order-items { font-size: 13.5px; color: var(--ink); overflow-wrap: anywhere; }
.order-note { font-size: 12.5px; color: var(--ink-dim); font-style: italic; overflow-wrap: anywhere; }
.order-meta { font-size: 12.5px; color: var(--ink-dim); overflow-wrap: anywhere; }
.order-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.chip-count { font-variant-numeric: tabular-nums; opacity: 0.8; }
#orderForm .status-label { margin-top: 14px; }
.order-status-toggle { flex-wrap: wrap; margin-bottom: 4px; }
.order-status-toggle .status-opt { min-width: 0; padding: 10px 6px; }
.danger-text { color: #e11d48; margin-right: auto; }

.check-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; color: var(--ink); cursor: pointer;
  margin: 4px 0 12px;
}
.check-row input[type="checkbox"] {
  /* กฎ input ทั่วไปตั้ง appearance: none ไว้กัน Safari แต่งช่องกรอก ซึ่งทำให้ checkbox หายไปทั้งอัน */
  -webkit-appearance: checkbox;
  appearance: auto;
  width: 20px; height: 20px; margin: 0;
  accent-color: var(--blue); flex-shrink: 0;
}
.ship-box {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px 2px;
  margin-bottom: 14px;
}
.ship-box .field { margin-bottom: 12px; }

.share-code-line { margin: 0 0 14px; color: var(--ink-dim); }
.share-code { color: var(--ink); font-size: 20px; letter-spacing: 0.12em; margin-left: 6px; }
.share-preview { display: inline-block; font-size: 13px; color: var(--blue); margin: 0 0 6px; text-decoration: none; font-weight: 500; }
.share-preview:hover { text-decoration: underline; }
#orderShareText { min-height: 84px; }

@media (max-width: 480px) {
  .order-row { flex-direction: column; align-items: stretch; }
  .order-actions { justify-content: flex-end; }
  #addOrderBtn { flex: 1 1 100%; }
  #orderFilterChips .chip { padding: 9px 4px; font-size: 13px; }
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
}
@media (max-width: 780px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: span 1; }

  .main-nav-top { display: none; }
  .topbar { flex-wrap: nowrap; align-items: flex-start; }
  .logout-btn, .refresh-btn { padding: 10px; border-radius: 999px; }
  .logout-btn .logout-label, .refresh-btn .logout-label { display: none; }
  body.logged-in .main-nav-bottom { display: flex; }
  .app { padding-bottom: 96px; }
  .bulk-action-bar { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .brand h1 { font-size: 19px; }
  .brand p { font-size: 12px; }
  .brand-emoji { font-size: 28px; }
  .app { padding: 18px 14px calc(96px + env(safe-area-inset-bottom, 0px)); }
  .wallet-panel, .toolbar { padding: 16px; }
  .wallet-actions { flex-direction: column; }
  .wallet-actions .btn { width: 100%; }
  .modal { padding: 20px 18px 20px; }
  .cost-item-row { flex-wrap: wrap; }
  .cost-item-row input[type="text"] { flex: 1 1 100%; }
  .cost-item-row input[type="number"] { flex: 1 1 auto; width: auto; }
  /* จัดแถบเครื่องมือให้อยู่ใน 3 แถวแทนที่จะเรียงลงมาทีละอัน 5 แถว
     แถว 1 ช่องค้นหา / แถว 2 ตัวกรอง / แถว 3 มุมมอง + เลือกหลายชิ้น + เพิ่มสินค้า */
  .toolbar { gap: 10px; }
  .search-box { flex: 1 1 100%; min-width: 0; }
  .filter-chips { flex: 1 1 100%; justify-content: space-between; }
  .chip { flex: 1; text-align: center; padding: 9px 8px; }
  .view-toggle { flex: 0 0 auto; }
  #selectModeBtn { flex: 1 1 auto; padding: 12px 12px; font-size: 13.5px; white-space: nowrap; }
  #addProductBtn { flex: 0 0 auto; padding: 12px 16px; }
  .toolbar-selects { flex: 1 1 100%; }
  .toolbar-select { flex: 1; max-width: none; }
  .image-cell { width: 76px; height: 76px; }
  .lightbox-close { top: -44px; }
  .card-footer { flex-direction: column; }
  .bulk-action-bar { left: 12px; right: 12px; transform: none; width: auto; justify-content: space-between; }
  .sold-item-row { flex-wrap: wrap; }
  .sold-item-price { align-items: flex-start; width: 100%; flex-direction: row; justify-content: space-between; }
  .sold-item-price-input { width: 120px; }
}
