:root {
  --bg: #f4f5fb;
  --card: #ffffff;
  --ink: #1c1f2e;
  --muted: #6b7280;
  --line: #e6e8f0;
  --primary: #4f46e5;
  --primary-d: #4338ca;
  --green: #16a34a;
  --red: #dc2626;
  --field: #fbfbfe;             /* input idle background */
  --field-on: #ffffff;          /* input focus background */
  /* used by report cards / AI quota / ai-live — were referenced but never
     defined, leaving those surfaces transparent */
  --panel: #ffffff;
  --bg2: #eef0f7;
  --bar: rgba(255,255,255,.92); /* translucent top/bottom/pos bars */
  --radius: 16px;
  --shadow: 0 1px 3px rgba(20,22,40,.06), 0 6px 24px rgba(20,22,40,.05);
  /* iOS-style motion curves. --ease-ios is Apple's signature smooth decelerate
     (used for sheets/modals); --spring overshoots slightly then settles, giving
     the "bouncy pop" you feel on iPhone button/card interactions. */
  --ease-ios: cubic-bezier(0.32, 0.72, 0, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  /* gentler spring: overshoots only slightly, settles soft — for moving elements */
  --spring-soft: cubic-bezier(0.3, 1.28, 0.5, 1);
}
[data-theme="dark"] {
  --bg: #0f1117;
  --card: #1a1d27;
  --ink: #e7e9f0;
  --muted: #9aa1b2;
  --line: #2a2e3c;
  --field: #232734;
  --field-on: #2b3040;
  --panel: #1a1d27;
  --bg2: #232734;
  --bar: rgba(16,18,26,.88);
  --shadow: 0 1px 2px rgba(0,0,0,.5), 0 6px 24px rgba(0,0,0,.4);
}
/* dark-only fixes for surfaces whose text/bg don't come from the variables above */
[data-theme="dark"] .badge.sold { background: var(--line); color: var(--muted); }
[data-theme="dark"] .seg { background: #232734; }
[data-theme="dark"] .seg-btn.active { background: #313647; color: #c7d2fe; }
[data-theme="dark"] .prod-tags,
[data-theme="dark"] .d-tags,
[data-theme="dark"] .prod-filter > summary { color: #a5b4fc; }
[data-theme="dark"] .cart-rm { background: var(--field); }
[data-theme="dark"] .pa-btn:active,
[data-theme="dark"] .staff-btn:active,
[data-theme="dark"] .photo-add:active { background: var(--field-on); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Sukhumvit Set", "Noto Sans Thai", sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 15px; line-height: 1.5;
}
.hidden { display: none !important; }
/* visually hidden but still triggerable by its <label> (Safari won't open a
   file dialog for a display:none input, so we move it off-screen instead) */
.vis-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; font-size: 16px; }
/* modern dropdowns: strip the native glossy chrome (Safari/WebKit ignores
   custom background otherwise) and draw our own chevron. Contexts must use
   background-color (not the background shorthand) or they'd wipe this chevron. */
select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px 16px;
  padding-right: 38px;
  cursor: pointer;
}
select::-ms-expand { display: none; }
[data-theme="dark"] select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239aa1b2' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}
/* number fields: type only, no up/down spinner */
input[type=number]::-webkit-outer-spin-button, input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #6366f1 0%, #4f46e5 35%, #312e81 100%);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--card);
  border-radius: 20px; padding: 28px 24px 24px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}
.brand { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.brand span { color: var(--primary); }
.login-sub { margin: -6px 0 4px; color: var(--muted); font-size: 14px; }
.login-card label, #add-form label, .search-row label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.login-card input, #add-form input, #add-form select {
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background-color: var(--field); color: var(--ink);
}
.login-card input:focus, #add-form input:focus, #add-form select:focus { outline: none; border-color: var(--primary); background-color: var(--field-on); }

/* ---------- Buttons ---------- */
.btn-primary {
  background: var(--primary); color: #fff; border: 0; padding: 13px 16px; border-radius: 12px;
  font-weight: 700; font-size: 15px; transition: background .15s;
}
.btn-primary:active { background: var(--primary-d); }
.btn-primary:disabled { opacity: .6; }
.btn-primary.small { padding: 10px 14px; white-space: nowrap; }
.btn-primary.wide, .btn-ghost.wide { width: 100%; }
.btn-ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  padding: 9px 14px; border-radius: 10px; font-weight: 600; font-size: 13px;
}

/* Tactile press feedback. Animates only transform/background (GPU-friendly, no
   layout reflow) and stays short + subtle so taps feel responsive, not laggy.
   Honours prefers-reduced-motion for users who opt out of animation. */
.btn-primary, .btn-ghost, .btn-danger, .pa-btn, .staff-btn {
  /* Release springs back with a tiny overshoot (the iPhone "pop"). */
  transition: background .15s ease, transform .42s var(--spring);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn-primary:active, .btn-ghost:active, .btn-danger:active, .pa-btn:active, .staff-btn:active {
  transform: scale(.94);
  /* Press-down is snappy, not springy — feels instant under the finger. */
  transition: transform .08s ease-out;
}
.btn-primary:disabled, .btn-ghost:disabled, .pa-btn:disabled { transform: none; }
@media (prefers-reduced-motion: reduce) {
  .btn-primary, .btn-ghost, .btn-danger, .pa-btn, .staff-btn { transition: background .15s ease; }
  .btn-primary:active, .btn-ghost:active, .btn-danger:active, .pa-btn:active, .staff-btn:active { transform: none; }
}

.err { color: var(--red); font-size: 13px; margin: 4px 0 0; }
.msg { font-size: 14px; margin: 10px 0 0; padding: 10px 12px; border-radius: 10px; }
.msg.ok { background: #ecfdf5; color: var(--green); }
.msg.bad { background: #fef2f2; color: var(--red); }

/* ---------- App shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; padding-top: max(14px, env(safe-area-inset-top));
  background: var(--bar); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar .shop { font-weight: 800; font-size: 16px; }
.topbar .user { font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; padding: 8px 10px; }
.icon-btn svg { display: block; }
#main { padding: 16px 16px 96px; max-width: 720px; margin: 0 auto; position: relative; overflow-x: hidden; }
@supports (overflow-x: clip) { #main { overflow-x: clip; } }
.view-title { font-size: 20px; font-weight: 800; margin: 4px 0 16px; }
.section-title { font-size: 14px; font-weight: 700; color: var(--muted); margin: 22px 0 10px; }

/* ---------- Dashboard ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat-card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; overflow: hidden; }
.stat-card.full { grid-column: 1 / -1; }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat-value { font-size: clamp(18px, 6vw, 26px); font-weight: 800; margin-top: 4px; letter-spacing: -.5px; overflow-wrap: anywhere; }
.stat-value small { font-size: 14px; font-weight: 600; color: var(--muted); }

.cat-list { display: flex; flex-direction: column; gap: 8px; }
.cat-row {
  display: flex; align-items: center; gap: 12px; background: var(--card);
  border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow);
}
.cat-dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; border: 1px solid rgba(0,0,0,.1); }
.cat-name { font-weight: 700; flex: 1; }
.cat-meta { text-align: right; font-size: 13px; }
.cat-count { font-weight: 800; }
.cat-cost { color: var(--muted); font-size: 12px; }

/* ---------- Products ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; -webkit-overflow-scrolling: touch; }
.chip {
  white-space: nowrap; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
}
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.search-row { display: flex; gap: 8px; margin-bottom: 14px; }
/* min-width:0 lets the input shrink instead of pushing the buttons off-screen */
.search-row input { flex: 1; min-width: 0; padding: 11px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--field); }
.search-row > .btn-primary, .search-row > .btn-ghost { flex: 0 0 auto; }
.prod-list { display: flex; flex-direction: column; gap: 8px; }
.prod-card { background: var(--card); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.prod-top { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.prod-top:active { opacity: .7; }
.prod-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.pa-btn { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--field); color: var(--ink); border-radius: 9px; padding: 9px 0; font-weight: 700; font-size: 13px; }
.pa-btn:active { background: #eef0f8; }
.pa-btn.sell { background: var(--primary); color: #fff; border-color: var(--primary); }
.pa-btn.move { color: var(--primary); border-color: #c7d2fe; background: #eef2ff; flex: 0 0 auto; padding: 9px 14px; }
.pa-btn.del { color: var(--red); border-color: #fecaca; flex: 0 0 auto; padding: 9px 16px; }
.pa-btn.save { background: var(--green); color: #fff; border-color: var(--green); flex: 0 0 auto; padding: 9px 16px; }
.pa-price { flex: 1; min-width: 80px; border: 1px solid var(--primary); border-radius: 9px; padding: 9px 12px; font-size: 16px; background: var(--field); color: var(--ink); }
.pa-price:focus { outline: none; }
.prod-main { flex: 1; min-width: 0; }
.prod-tags { font-size: 11px; color: var(--primary-d); margin-top: 3px; font-weight: 600; }
.group-card { border-left: 3px solid var(--primary); }
.group-count { display: inline-block; margin-left: 8px; padding: 1px 8px; background: var(--primary); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; vertical-align: middle; }
.group-caret { display: inline-block; margin-left: 6px; color: var(--muted); font-size: 14px; }
.group-items { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); display: flex; flex-direction: column; gap: 8px; }
.group-items .prod-card { background: var(--field); box-shadow: none; padding: 10px 12px; }

/* attribute filter */
.prod-filter { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); margin-bottom: 12px; padding: 4px 0; }
.prod-filter > summary { cursor: pointer; padding: 11px 14px; font-weight: 700; font-size: 13px; color: var(--primary-d); list-style: none; }
.prod-filter > summary::-webkit-details-marker { display: none; }
.prod-filter[open] > summary { border-bottom: 1px solid var(--line); }
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 14px 6px; }
.filter-grid select { padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; background-color: var(--field); color: var(--ink); font-size: 14px; min-width: 0; transition: border-color .15s, background-color .15s; }
.filter-grid select:focus { outline: none; border-color: var(--primary); background-color: var(--field-on); }
#prod-sort { padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; background-color: var(--field); color: var(--ink); font-size: 14px; min-width: 0; transition: border-color .15s, background-color .15s; }
#prod-sort:focus { outline: none; border-color: var(--primary); background-color: var(--field-on); }
.filter-foot { display: flex; align-items: center; justify-content: space-between; padding: 4px 14px 12px; }
.filter-count { font-size: 12px; color: var(--muted); font-weight: 700; }
.prod-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prod-sub { font-size: 12px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.prod-right { text-align: right; }
.prod-cost { font-weight: 800; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; margin-top: 4px; }
.badge.in { background: #ecfdf5; color: var(--green); }
.badge.sold { background: #f3f4f6; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ---------- Add stock ---------- */
#add-form { display: flex; flex-direction: column; gap: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
/* let grid cells shrink so inputs never overflow the sheet */
.row2 > *, .row3 > * { min-width: 0; }
.qform input, .qform select { width: 100%; min-width: 0; }
.d-tags { font-size: 12px; color: var(--primary-d); font-weight: 600; margin-top: 8px; overflow-wrap: anywhere; }
.photo-zone { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.photo-previews { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-previews:empty { display: none; }
.photo-thumb { position: relative; width: 76px; height: 76px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb .rm {
  position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff; border: 0; font-size: 14px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.photo-native { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--muted); }
.photo-native input[type=file] { font-size: 13px; max-width: 100%; }
.photo-hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; text-align: center; }
.enqueue-row { display: flex; gap: 8px; margin-top: 10px; }
.enqueue-row > button { flex: 1; min-width: 0; }
.enqueue-row.hidden { display: none; }
.scan-status {
  margin-top: 10px; padding: 10px 12px; border-radius: 10px; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.scan-status.work { background: #eef2ff; color: var(--primary-d); }
.scan-status.ok { background: #ecfdf5; color: var(--green); }
.scan-status.bad { background: #fef2f2; color: var(--red); }
#rescan-btn { margin-top: 10px; }
.bc-row { display: flex; gap: 8px; }
.bc-row input { flex: 1; }
.bc-row .btn-ghost { flex: 0 0 auto; }
.photo-add {
  display: flex; align-items: center; justify-content: center; margin-top: 10px;
  border: 1.5px dashed #c7cbe0; border-radius: 12px; padding: 18px; color: var(--primary); font-weight: 700;
  width: 100%; background: transparent; font-family: inherit; font-size: 15px; cursor: pointer;
}
.photo-add:active { background: #f5f5ff; }
.photo-previews:empty + .photo-add { margin-top: 0; }

/* ---------- Bottom nav ---------- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-around; align-items: stretch;
  background: var(--bar); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1; background: none; border: 0; color: var(--muted); font-size: 11px; font-weight: 600;
  padding: 9px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.nav-btn .nav-ic { font-size: 19px; line-height: 1; }
.nav-btn.active { color: var(--primary); }
/* during a swipe each pane becomes an opaque page-card (iOS app switcher
   style) so the two pages can't visually bleed through each other */
.view.swipe-pane {
  background: var(--bg);
  border-radius: 16px;
  /* panes are opaque, so this is only a faint lift — heavy shadow showed an
     ugly dark edge while dragging on big screens */
  box-shadow: 0 6px 22px rgba(2, 6, 23, .08);
  min-height: 70vh;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom));
  background: #1c1f2e; color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); z-index: 50; max-width: 90%; text-align: center;
  /* Springs up into view, fades straight out — the iOS toast feel. */
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  transition: transform .45s var(--spring), opacity .25s ease;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .toast { transition: opacity .2s ease; transform: translate(-50%, 0); }
}

/* ---------- scan queue ---------- */
.queue-list { display: flex; flex-direction: column; gap: 12px; }
.qcard { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); overflow: hidden; }
.qcard * { min-width: 0; max-width: 100%; }
.qsaved, .q-msg { overflow-wrap: anywhere; }
.qcard.ready { border: 1.5px solid #c7d2fe; }
.qcard-top { display: flex; align-items: center; gap: 10px; }
.qthumbs { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.qthumbs img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; transition: transform .12s ease; }
.qthumbs img:hover { transform: scale(1.04); }
.badge.work { background: #eef2ff; color: var(--primary-d); }
.badge.wait { background: #fef9c3; color: #854d0e; }
.badge.ready { background: #ecfdf5; color: var(--green); }
.qdetected { font-size: 12px; color: var(--muted); margin: 10px 0 4px; overflow-wrap: anywhere; word-break: break-word; }
.qdup { background: #fef2f2; color: var(--red); font-size: 12px; font-weight: 700; padding: 8px 10px; border-radius: 8px; margin: 6px 0 2px; }
.qcard.ready:has(.qdup) { border-color: #fecaca; }
.qform { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.qform label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 600; }
.qform input, .qform select { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background-color: var(--field); color: var(--ink); font-size: 16px; }
.qform input:focus, .qform select:focus { outline: none; border-color: var(--primary); background-color: var(--field-on); }
.qactions { display: flex; gap: 8px; margin-top: 12px; }
.qactions .btn-primary { flex: 1; }
.q-msg { font-size: 13px; margin: 8px 0 0; }
.q-msg.bad { color: var(--red); }
.qsaved { color: var(--green); font-weight: 700; font-size: 14px; }
.navbadge {
  position: absolute; top: 4px; right: 50%; transform: translateX(20px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff;
  font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center;
}
.nav-btn { position: relative; }

/* spinner */
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: sp .7s linear infinite; vertical-align: -3px; }
@keyframes sp { to { transform: rotate(360deg); } }
.loading { text-align: center; color: var(--muted); padding: 30px 0; }

/* ---------- products: scan button ---------- */
.btn-ghost.small { padding: 10px 12px; white-space: nowrap; }
.btn-ghost.small.icon { color: var(--primary); border-color: #c7d2fe; }

/* ---------- monthly chart ---------- */
.month-chart { background: var(--card); border-radius: var(--radius); padding: 16px 14px 12px; box-shadow: var(--shadow); }
.mc-grid { display: flex; align-items: flex-end; justify-content: space-between; gap: 6px; height: 84px; }
.mc-col { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.mc-bars { display: flex; align-items: flex-end; gap: 3px; height: 64px; }
.mc-bar { width: 6px; min-height: 2px; border-radius: 3px 3px 0 0; }
.mc-label { font-size: 10px; color: var(--muted); white-space: nowrap; }
.mc-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.mc-leg { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); font-weight: 600; }
.mc-leg-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* ---------- activity feed ---------- */
.activity-list { display: flex; flex-direction: column; gap: 0; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.act-row { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.act-row:last-child { border-bottom: 0; }
.act-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; margin-top: 6px; background: var(--muted); }
.act-dot.success { background: var(--green); }
.act-dot.danger { background: var(--red); }
.act-dot.warning { background: #f59e0b; }
.act-dot.info, .act-dot.primary { background: var(--primary); }
.act-body { min-width: 0; flex: 1; }
.act-text { font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }
.act-meta { font-size: 11px; color: var(--muted); margin-top: 3px; }

/* ---------- bottom sheet (product detail) ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(15,17,30,.5); backdrop-filter: blur(2px); animation: backdropin .4s ease; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; background: var(--card);
  border-radius: 22px 22px 0 0; padding: 8px 18px calc(22px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto; box-shadow: 0 -8px 40px rgba(0,0,0,.25);
  animation: sheetup .5s var(--ease-ios); max-width: 720px; margin: 0 auto;
}
@keyframes sheetup { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes backdropin { from { opacity: 0; } to { opacity: 1; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: #d4d7e3; margin: 6px auto 14px; }
.d-head { display: flex; align-items: flex-start; gap: 10px; justify-content: space-between; }
.d-title { font-size: 19px; font-weight: 800; line-height: 1.3; }
.d-head .badge { margin-top: 4px; flex: 0 0 auto; }
.d-cat { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 700; color: var(--ink); margin-top: 10px; }
.d-grid { display: flex; flex-direction: column; margin-top: 16px; }
.d-row { display: flex; justify-content: space-between; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.d-label { color: var(--muted); font-size: 13px; font-weight: 600; flex: 0 0 auto; }
.d-val { text-align: right; font-weight: 700; overflow-wrap: anywhere; }
.d-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.d-actions .btn-primary, .d-actions .btn-ghost { flex: 1 1 auto; min-width: 84px; white-space: nowrap; }

/* ---------- access-token gate ---------- */
.gate-input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--field); color: var(--ink);
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.5; resize: vertical; word-break: break-all;
}
.gate-input:focus { outline: none; border-color: var(--primary); background: var(--field-on); }

/* ---------- POS (cart sell) ---------- */
.pos-results { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.pos-find-row, .cart-row { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); }
.pos-find-main, .cart-main { flex: 1; min-width: 0; }
.pos-cart { display: flex; flex-direction: column; gap: 8px; padding-bottom: 60px; } /* clear the fixed คิดเงิน bar + nav */
.cart-price { width: 96px; flex: 0 0 auto; padding: 9px 10px; border: 1px solid var(--primary); border-radius: 9px; font-size: 16px; text-align: right; background: var(--field); color: var(--ink); }
.cart-price:focus { outline: none; }
.cart-rm { flex: 0 0 auto; width: 32px; height: 32px; border-radius: 8px; border: 1px solid #fecaca; background: #fff; color: var(--red); font-size: 15px; }
.pos-bar {
  position: fixed; left: 0; right: 0; bottom: calc(58px + env(safe-area-inset-bottom)); z-index: 30;
  display: flex; align-items: center; gap: 10px; max-width: 720px; margin: 0 auto;
  background: var(--bar); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
  padding: 10px 14px; box-shadow: 0 -6px 24px rgba(20,22,40,.1);
}
.pos-bar-info { display: flex; flex-direction: column; line-height: 1.2; }
.pos-bar-info span { font-size: 11px; color: var(--muted); }
.pos-bar-info strong { font-size: 20px; font-weight: 800; }
.pos-pay { padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--field); color: var(--ink); font-size: 14px; }
.pos-bar .btn-primary { flex: 1; }

/* ---------- staff picker / PIN (login + lock) ---------- */
.staff-pick { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.staff-btn {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--field); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; font-size: 15px; font-weight: 700; color: var(--ink);
}
.staff-btn:active { background: #f0f0fb; }
.staff-av { width: 38px; height: 38px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; flex: 0 0 auto; text-transform: uppercase; }
.staff-btn.admin .staff-av { background: #312e81; }
.staff-nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.staff-tag { font-size: 11px; font-weight: 700; color: var(--primary); background: #eef2ff; padding: 3px 8px; border-radius: 999px; }
.pin-area { display: flex; flex-direction: column; gap: 6px; }
.pin-area .btn-primary, .pin-area .btn-ghost { margin-top: 2px; }
.pin-who { font-size: 16px; font-weight: 800; text-align: center; margin-bottom: 2px; }
#login-pin { padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--field); color: var(--ink); text-align: center; font-size: 22px; letter-spacing: 8px; }
#login-pin:focus { outline: none; border-color: var(--primary); background: var(--field-on); }
/* letter-spacing displaces Thai combining marks (ใส่ → ใส') — placeholder only */
#login-pin::placeholder { letter-spacing: normal; }

/* ---------- admin ---------- */
.seg { display: flex; gap: 6px; background: #eceefb; border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.seg-btn { flex: 1; border: 0; background: transparent; padding: 9px 0; border-radius: 9px; font-weight: 700; font-size: 13px; color: var(--muted); }
.seg-btn.active { background: #fff; color: var(--primary); box-shadow: var(--shadow); }
/* Admin's segmented control has grown to ~10 tabs and the flex:1 layout
   crushes each one into a 2-line wrap. Switch it to a horizontal scroll
   strip where each tab keeps its natural width and the active tab gets
   scrolled into view by JS. */
#admin-seg { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
#admin-seg::-webkit-scrollbar { display: none; }
#admin-seg .seg-btn { flex: 0 0 auto; padding: 9px 14px; white-space: nowrap; }
.admin-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.admin-row { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.admin-row.off { opacity: .55; }
.admin-row-main { flex: 1; min-width: 0; }
.admin-row-name { font-weight: 700; }
.admin-row-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.role-card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 12px; }
.role-name { font-weight: 800; margin-bottom: 8px; }
.role-cap { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; font-weight: 600; }
.role-cap input { width: 20px; height: 20px; accent-color: var(--primary); }
.audit-filters { display: flex; gap: 8px; margin-bottom: 12px; }
.audit-filters select { flex: 1; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background-color: var(--field); color: var(--ink); font-size: 14px; }
.audit-list { display: flex; flex-direction: column; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.audit-item { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.audit-item:last-child { border-bottom: 0; }
.audit-main { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.audit-act { display: inline-block; font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px; margin-right: 6px; background: #eef2ff; color: var(--primary-d); }
.audit-act.a-sell { background: #ecfdf5; color: var(--green); }
.audit-act.a-delete { background: #fef2f2; color: var(--red); }
.audit-act.a-edit { background: #fef9c3; color: #854d0e; }
.audit-det { font-size: 12px; color: var(--ink); margin-top: 3px; }
.audit-meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.btn-ghost.danger { color: var(--red); border-color: #fecaca; background: #fef2f2; }
.recheck-pin {
  width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--primary);
  background: #fff; color: var(--primary); font-size: 14px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  margin-top: 6px; cursor: pointer; transition: background .15s, transform .12s;
  box-shadow: 0 2px 6px rgba(79,70,229,.18);
}
.recheck-pin:hover { background: #eef2ff; }
.recheck-pin:active { transform: scale(.92); }
.recheck-pin:disabled { opacity: .6; cursor: default; }
.btn-ghost.danger:active { background: #fee2e2; }
.btn-danger {
  background: var(--red); color: #fff; border: 0; padding: 13px 16px; border-radius: 12px;
  font-weight: 700; font-size: 15px; transition: background .15s;
}
.btn-danger:active { background: #b91c1c; }
.btn-danger:disabled { opacity: .6; }
.nav-btn .nav-ic { font-size: 19px; }

/* ---------- live scanner ---------- */
.scan-wrap { position: fixed; inset: 0; z-index: 70; background: #000; display: flex; align-items: center; justify-content: center; }
#scan-video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(94vw, 520px); height: min(55vh, 380px);
  border: 3px solid rgba(255,255,255,.9);
  border-radius: 18px; box-shadow: 0 0 0 9999px rgba(0,0,0,.45);
}
/* thin red aiming line, like a handheld barcode scanner */
.scan-frame::after { content: ''; position: absolute; top: 50%; left: 14px; right: 14px; height: 2px; transform: translateY(-50%); background: rgba(239,68,68,.85); border-radius: 2px; }
.scan-hint { position: absolute; bottom: 18%; left: 0; right: 0; text-align: center; color: #fff; font-size: 14px; font-weight: 600; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.scan-x {
  position: absolute; top: max(16px, env(safe-area-inset-top)); right: 16px;
  background: rgba(255,255,255,.92); color: #1c1f2e; border: 0; border-radius: 999px;
  padding: 9px 18px; font-weight: 700; font-size: 14px;
}
.scan-tools { position: absolute; bottom: calc(8% + env(safe-area-inset-bottom)); left: 0; right: 0; display: flex; gap: 10px; justify-content: center; }
.scan-tool { background: rgba(255,255,255,.92); color: #1c1f2e; border: 0; border-radius: 999px; padding: 11px 20px; font-weight: 700; font-size: 14px; }
.scan-tool.on { background: #fde047; }

/* ---------- condition toggle (มือ 1 / มือ 2) ---------- */
.cond-toggle { display: flex; gap: 6px; background: var(--field); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.cond-opt { flex: 1; border: 0; background: transparent; padding: 10px 0; border-radius: 9px; font-weight: 700; font-size: 13px; color: var(--muted); }
.cond-opt.active { background: var(--card); color: var(--primary); box-shadow: var(--shadow); }
[data-theme="dark"] .cond-opt.active { background: #313647; color: #c7d2fe; }

/* ---------- checkout sub-sheet ---------- */
.co-list { display: flex; flex-direction: column; margin-top: 14px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.co-row { display: flex; justify-content: space-between; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.co-row:last-child { border-bottom: 0; }
.co-name { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.co-price { width: 110px; flex: 0 0 auto; padding: 9px 10px; border: 1px solid var(--primary); border-radius: 9px; font-size: 16px; text-align: right; background: var(--field); color: var(--ink); }
.co-price:focus { outline: none; }
.co-pay-label { font-size: 13px; color: var(--muted); font-weight: 700; margin: 16px 0 8px; }
/* long item lists scroll inside their own box so the pay/total/confirm controls
   below stay reachable without scrolling the whole sheet. (No position:sticky —
   it triggers an iOS Safari repaint bug that blanks the sheet.) */
.co-list { max-height: 40vh; overflow-y: auto; }
.co-total { display: flex; align-items: baseline; justify-content: space-between; margin-top: 16px; padding-top: 14px; border-top: 2px solid var(--line); }
.co-total-label { font-size: 14px; color: var(--muted); font-weight: 700; }
.co-total-val { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }

/* ---------- installments (ผ่อน) ---------- */
.badge.due { background: #fef2f2; color: var(--red); }
[data-theme="dark"] .badge.due { background: rgba(220,38,38,.18); color: #fca5a5; }
.inst-cardfoot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.inst-line { font-size: 12px; color: var(--muted); flex: 1; min-width: 0; }
.inst-line.overdue { color: var(--red); font-weight: 700; }
.inst-line.soon { color: #b45309; font-weight: 700; }
[data-theme="dark"] .inst-line.soon { color: #fbbf24; }
.inst-cut { flex: 0 0 auto; padding: 7px 14px; }
.inst-cut.hot { background: #f59e0b; border-color: #f59e0b; }
.inst-line-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.inst-rem { font-size: 11px; }
.inst-rem-yes { color: var(--green); }
.inst-rem-no { color: var(--muted); }
.inst-cardfoot-actions { display: flex; gap: 6px; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; }
.inst-send { padding: 7px 12px; flex: 0 0 auto; }
.prod-card.inst-soon { border-left: 3px solid #f59e0b; }
.prod-card.inst-overdue { border-left: 3px solid var(--red); }
.badge.soon { background: #fff7ed; color: #b45309; }
[data-theme="dark"] .badge.soon { background: rgba(245,158,11,.2); color: #fbbf24; }
.inst-detailbar { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.inst-sched { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.inst-row { display: flex; align-items: center; gap: 10px; background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.inst-row.paid { opacity: .6; }
.inst-row-main { flex: 1; min-width: 0; }
.inst-period { font-weight: 700; font-size: 13px; }
.inst-amt { font-size: 12px; color: var(--muted); margin-top: 2px; }
.inst-row .pa-btn.save { flex: 0 0 auto; padding: 8px 14px; }
.inst-row .pa-btn { flex: 0 0 auto; padding: 8px 12px; }

/* LINE OA section in contract detail */
.line-section { margin-top: 18px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--field); }
.line-section .section-title { margin: 0 0 8px; }
.line-body .muted, .muted { color: var(--muted); font-size: 12px; }
.line-status-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.line-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.line-link-box { margin-top: 12px; padding: 10px; border-radius: 10px; background: var(--bg); border: 1px dashed var(--line); }
.line-link { display: block; word-break: break-all; font-size: 12px; color: var(--primary); margin-top: 6px; }
.line-qr { background: #fff; padding: 6px; border-radius: 10px; }

/* seg-btn count badge (used by "รออนุมัติสลิป") */
.seg-badge { display: inline-block; min-width: 18px; padding: 1px 6px; margin-left: 6px; font-size: 11px; line-height: 16px; border-radius: 9px; background: var(--red); color: #fff; font-weight: 800; }

/* admin slip review queue cards */
.queue-card { background: var(--field); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.queue-head { display: flex; flex-direction: column; gap: 2px; }
.queue-cust { font-weight: 700; font-size: 14px; }
.queue-reason { font-size: 12px; color: var(--red); }
.queue-slip { max-width: 100%; max-height: 360px; border-radius: 8px; align-self: center; background: #fff; }
.queue-meta { font-size: 12px; display: flex; flex-direction: column; gap: 2px; padding: 8px; background: var(--bg); border-radius: 8px; }
.queue-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.queue-actions .btn-primary, .queue-actions .btn-ghost { flex: 1; min-width: 0; }
.q-flag { display: inline-block; padding: 1px 8px; border-radius: 9px; font-size: 11px; font-weight: 700; }
.q-flag.good { background: rgba(10,124,47,.15); color: var(--green); }
.q-flag.bad { background: rgba(200,30,30,.15); color: var(--red); }
.small-mono { font-family: ui-monospace, "SF Mono", monospace; font-size: 11px; word-break: break-all; }
.queue-hr { border: 0; border-top: 1px dashed var(--line); margin: 6px 0; }

/* shop settings — payouts editor + integration status */
.payouts-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
/* row-gap: 12px gives wrapped fields (e.g. "ชื่อบัญชี" dropping below) vertical
   breathing room — otherwise the second row hugs the first one. */
.payout-row { display: flex; flex-wrap: wrap; gap: 12px 8px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--field); align-items: end; }
.payout-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; flex: 1 1 140px; }
.po-lbl { color: var(--muted); font-size: 11px; }
.payout-row input, .payout-row select { padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; background-color: var(--bg); color: var(--ink); }
.po-default { flex-direction: row !important; align-items: center !important; gap: 6px !important; flex: 1 1 100% !important; }
.po-default-disabled { font-size: 11px; color: var(--muted); font-style: italic; }
.qr-warn { background: #fff7ed; color: #b45309; border: 1px solid #fed7aa; border-radius: 10px; padding: 10px 12px; font-size: 13px; margin: 8px 0; }
[data-theme="dark"] .qr-warn { background: rgba(245,158,11,.15); color: #fbbf24; border-color: rgba(245,158,11,.3); }
.subsection-title { font-size: 13px; font-weight: 700; color: var(--ink); margin: 18px 0 8px; }
.qr-upload { padding: 12px; border: 1px dashed var(--line); border-radius: 10px; background: var(--bg); margin-bottom: 8px; }
.qr-preview { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.kind-row { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; }
.kind-row label { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.integration-box { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--field); margin-top: 8px; }
.toggle-row { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.integration-status { margin-top: 10px; display: flex; flex-direction: column; font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.is-row { display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; border-top: 1px solid var(--line); }
.is-row:first-child { border-top: 0; }
.is-val.ok { color: var(--green); font-weight: 600; }
.is-val.bad { color: var(--red); font-weight: 600; }
.addr-h { font-weight: 700; font-size: 13px; color: var(--primary-d); margin-top: 10px; }
[data-theme="dark"] .addr-h { color: #a5b4fc; }
.map-tools { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.pin-map { height: 220px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); z-index: 0; }
.pin-map .leaflet-control-attribution { font-size: 9px; }

/* ---------- printable contract ---------- */
#print-area { display: none; }
.contract { color: #000; background: #fff; font-size: 13px; line-height: 1.6; padding: 24px; max-width: 800px; margin: 0 auto; font-family: "Sarabun", "TH Sarabun New", "Noto Sans Thai", sans-serif; }
.contract .ct-head { text-align: center; margin-bottom: 14px; }
.contract .ct-shop { font-size: 18px; font-weight: 800; }
.contract .ct-shop-sub { font-size: 12px; color: #444; }
.contract h1 { font-size: 18px; margin: 10px 0 4px; }
.contract .ct-date { font-size: 12px; }
.contract .ct-sec { margin: 8px 0; padding: 8px 0; border-top: 1px solid #ccc; }
.contract .ct-line { margin-top: 3px; }
.contract .ct-table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 12px; }
.contract .ct-table th, .contract .ct-table td { border: 1px solid #999; padding: 5px 8px; }
.contract .ct-table .r { text-align: right; }
.contract .ct-terms ol { margin: 6px 0 0; padding-left: 20px; }
.contract .ct-terms li { margin-bottom: 4px; }
.contract .ct-signs { display: flex; justify-content: space-around; gap: 24px; margin-top: 36px; text-align: center; font-size: 12px; }
.contract .ct-sign { flex: 1; }
.contract .ct-sline { border-bottom: 1px dotted #000; height: 36px; margin-bottom: 6px; }
@media print {
  body > * { display: none !important; }
  #print-area { display: block !important; }
  @page { size: A4; margin: 14mm; }
}

/* ---------- AI usage widgets (quota meter + live banner) ---------- */
.ai-quota { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; }
.ai-quota .aq-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.ai-quota .aq-title { font-weight: 700; font-size: 13px; color: var(--ink); }
.ai-quota .aq-num { font-size: 12px; color: var(--muted); }
.ai-quota .aq-bar { height: 8px; border-radius: 999px; background: var(--bg2); overflow: hidden; }
.ai-quota .aq-fill { height: 100%; background: linear-gradient(90deg, #16a34a, #4f46e5); transition: width .35s ease; }
.ai-quota .aq-fill.warn { background: linear-gradient(90deg, #f59e0b, #ef4444); }
.ai-quota .aq-fill.full { background: #ef4444; }
.ai-quota .aq-foot { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 11px; color: var(--muted); margin-top: 6px; }
.ai-quota .aq-foot strong { color: var(--ink); font-weight: 600; }
.ai-quota .aq-keys { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.ai-quota .aq-key { font-size: 10px; padding: 2px 6px; border-radius: 6px; background: var(--bg2); color: var(--muted); }
.ai-quota .aq-key.hot { background: #fef3c7; color: #92400e; }
[data-theme="dark"] .ai-quota .aq-key.hot { background: #78350f; color: #fde68a; }

/* AI mode toggle (free key pool vs billed key) */
.ai-quota .aq-mode { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin: 8px 0; }
.ai-quota .aq-mode-label { font-size: 12px; font-weight: 600; color: var(--ink); }
.ai-quota .aq-mode-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.ai-quota .aq-mode-btn { font-size: 12px; padding: 4px 12px; border: 0; background: var(--bg2); color: var(--muted); cursor: pointer; }
.ai-quota .aq-mode-btn + .aq-mode-btn { border-left: 1px solid var(--line); }
.ai-quota .aq-mode-btn.on { background: #16a34a; color: #fff; font-weight: 600; }
.ai-quota .aq-mode-btn.on.paid { background: #ef4444; }
.ai-quota .aq-mode-hint { font-size: 11px; color: var(--muted); }
.ai-quota .aq-mode-badge { font-size: 11px; padding: 2px 8px; border-radius: 6px; font-weight: 600; }
.ai-quota .aq-mode-badge.free { background: #dcfce7; color: #166534; }
.ai-quota .aq-mode-badge.paid { background: #fee2e2; color: #991b1b; }
[data-theme="dark"] .ai-quota .aq-mode-badge.free { background: #14532d; color: #bbf7d0; }
[data-theme="dark"] .ai-quota .aq-mode-badge.paid { background: #7f1d1d; color: #fecaca; }

/* live banner shown while an AI call is in flight */
.ai-live { position: fixed; left: 12px; right: 12px; bottom: calc(78px + env(safe-area-inset-bottom)); z-index: 9000; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.ai-live-bar { height: 4px; border-radius: 999px; background: var(--bg2); overflow: hidden; margin-bottom: 6px; }
.ai-live-fill { height: 100%; width: 30%; border-radius: 999px; background: linear-gradient(90deg, #4f46e5, #16a34a); animation: aiSweep 1.2s ease-in-out infinite; }
@keyframes aiSweep { 0% { transform: translateX(-50%); } 100% { transform: translateX(280%); } }
.ai-live-text { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.ai-live-text #ai-live-label { color: var(--ink); font-weight: 600; }

/* ---------- product detail image thumbnails ---------- */
.d-row.d-images { flex-direction: column; align-items: stretch; gap: 8px; }
.d-row.d-images .d-label { text-align: left; }
.d-thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.d-thumb { width: 80px; height: 80px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; background: var(--bg2); transition: transform .12s ease; }
.d-thumb:hover { transform: scale(1.04); }

/* ---------- full-screen image lightbox ---------- */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 11000; display: flex; align-items: center; justify-content: center; padding: 24px; }
.lightbox.hidden { display: none; }
.lightbox .lb-img { max-width: min(98vw, 1600px); max-height: 92vh; object-fit: contain; border-radius: 6px; box-shadow: 0 12px 60px rgba(0,0,0,.4); }
.lightbox .lb-close { position: absolute; top: 12px; right: 16px; width: 48px; height: 48px; border-radius: 50%; border: none; background: rgba(0,0,0,.55); color: #fff; font-size: 22px; cursor: pointer; z-index: 10; }
.lightbox .lb-close:hover { background: rgba(255,255,255,.28); }

/* ---------- installment list breathing room ---------- */
#inst-summary { margin-bottom: 14px; }
#inst-list-pane > .chips { margin-top: 6px; margin-bottom: 12px; }
#inst-list-pane > .search-row { margin-bottom: 14px; }

/* ---------- daily report page ---------- */
.report-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.report-bar input[type="date"] { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font-size: 14px; }
.report-bar .btn-ghost { padding: 6px 12px; font-size: 13px; }
.report-totals { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 16px; }
.report-totals .rt-head { font-weight: 700; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.report-totals .rt-grand { font-size: 28px; font-weight: 800; color: var(--ink); }
.report-totals .rt-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; font-size: 13px; }
.report-totals .rt-grid > div { background: var(--bg2); padding: 8px 10px; border-radius: 8px; }
.report-totals .rt-grid strong { display: block; font-size: 15px; margin-top: 2px; color: var(--ink); }
.report-section { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 14px; }
.report-section h3 { margin: 0 0 8px; font-size: 14px; color: var(--ink); display: flex; justify-content: space-between; gap: 8px; }
.report-section h3 .rs-count { color: var(--muted); font-size: 12px; font-weight: 500; }
.report-cat { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }
.report-cat:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.report-cat-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.report-row { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); padding: 4px 0; border-bottom: 1px dashed var(--line); }
.report-row:last-child { border-bottom: 0; }
.report-row .rr-name { color: var(--ink); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.report-row .rr-amt { font-weight: 600; color: var(--ink); }
.report-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 14px; }
/* editable sold-item row + inline price/cost editor */
.report-row.editable { cursor: pointer; }
.report-row.editable .rr-edit { flex: 0 0 auto; font-size: 12px; opacity: .55; margin-left: 2px; }
.report-row.editable:active { opacity: .7; }
.rr-editor { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 4px 0 8px; display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.rr-editor .rr-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.rr-editor .rr-field input { width: 110px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); font-size: 15px; }
.rr-editor-actions { display: flex; gap: 8px; margin-left: auto; }

/* ---------- daily sales heatmap (devices sold / day, green calendar) ---------- */
.report-heatmap { margin: 4px 0 14px; }
.hm-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 14px; font-weight: 700; color: var(--ink); margin: 0 0 8px; }
.hm-head .rs-count { color: var(--muted); font-size: 12px; font-weight: 500; }
.hm-cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.hm-dow { text-align: center; font-size: 10px; color: var(--muted); font-weight: 600; padding-bottom: 2px; }
.hm-pad { aspect-ratio: 1 / 1; }
.hm-day { aspect-ratio: 1 / 1; border-radius: 7px; border: 1px solid var(--line); position: relative; display: flex; align-items: center; justify-content: center; background: transparent; cursor: pointer; transition: transform .07s ease; }
.hm-day:active { transform: scale(.92); }
/* calendar selection: single picked day, or a highlighted preset range (week/month) */
/* amber frame stands out from the green fills; inset so it never bleeds into
   neighbouring cells (no overlapping look) */
.hm-day.sel { z-index: 2; box-shadow: inset 0 0 0 3px #f59e0b; }
.hm-day.in-range { z-index: 1; box-shadow: inset 0 0 0 2px #f59e0b; }
.hm-day.range-start, .hm-day.range-end { z-index: 2; box-shadow: inset 0 0 0 3px #f59e0b; }
/* day number + count colors are set inline per-cell from the fill lightness
   (see heatColor in app.js); these are just the empty-cell defaults */
.hm-dnum { position: absolute; top: 3px; left: 5px; font-size: 9px; color: var(--muted); opacity: .75; line-height: 1; }
.hm-dcount { font-size: 16px; font-weight: 800; color: var(--ink); }
.hm-legend { display: flex; align-items: center; gap: 5px; margin-top: 8px; justify-content: flex-end; }
.hm-leg-lbl { font-size: 10px; color: var(--muted); }
.hm-leg-sw { width: 15px; height: 15px; border-radius: 4px; border: 1px solid var(--line); }

/* ---------- quota meter: reset countdown ---------- */
.ai-quota .aq-reset { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--muted); margin-top: 6px; }
.ai-quota .aq-refresh { background: transparent; border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; font-size: 11px; cursor: pointer; color: var(--muted); }
.ai-quota .aq-refresh:hover { color: var(--ink); }

/* === Animate.css v4.1.1 (extracted: fadeIn) — view tab transitions === */
.animate__animated {
  -webkit-animation-duration: 1s; animation-duration: 1s;
  -webkit-animation-duration: var(--animate-duration, 1s); animation-duration: var(--animate-duration, 1s);
  -webkit-animation-fill-mode: both; animation-fill-mode: both;
}
@media (prefers-reduced-motion: reduce), print {
  .animate__animated {
    -webkit-animation-duration: 1ms !important; animation-duration: 1ms !important;
    -webkit-transition-duration: 1ms !important; transition-duration: 1ms !important;
    -webkit-animation-iteration-count: 1 !important; animation-iteration-count: 1 !important;
  }
}
/* small slide-up + fade for full views (fadeInUp moves 100% — too much here) */
@-webkit-keyframes viewIn { 0% { opacity: 0; -webkit-transform: translate3d(0, 16px, 0); transform: translate3d(0, 16px, 0); } to { opacity: 1; -webkit-transform: none; transform: none; } }
@keyframes viewIn { 0% { opacity: 0; -webkit-transform: translate3d(0, 16px, 0); transform: translate3d(0, 16px, 0); } to { opacity: 1; -webkit-transform: none; transform: none; } }
.animate__viewIn { -webkit-animation-name: viewIn; animation-name: viewIn; }
/* snappy duration + easing for bottom-nav view switches */
.view-anim { --animate-duration: .32s; -webkit-animation-timing-function: cubic-bezier(.22,.61,.36,1); animation-timing-function: cubic-bezier(.22,.61,.36,1); }
/* direction-aware view switch: slides in from the side of travel with the
   same soft spring overshoot as button presses */
@keyframes viewInR { from { opacity: 0; transform: translate3d(40px, 0, 0); } to { opacity: 1; transform: none; } }
@keyframes viewInL { from { opacity: 0; transform: translate3d(-40px, 0, 0); } to { opacity: 1; transform: none; } }
.animate__viewInR { animation-name: viewInR; }
.animate__viewInL { animation-name: viewInL; }
.animate__viewInR, .animate__viewInL { --animate-duration: .36s; animation-timing-function: var(--spring-soft); }

/* === R2: tap targets — invisible hit-area extension to ≥44px, zero layout shift === */
.chip, .btn-ghost, .pa-btn, .seg-btn, .cond-opt, .cart-rm, .recheck-pin, .icon-btn, .scan-tool, .photo-thumb .rm { position: relative; }
.chip::after, .btn-ghost::after, .pa-btn::after, .seg-btn::after, .cond-opt::after,
.cart-rm::after, .recheck-pin::after, .icon-btn::after, .scan-tool::after {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: max(100%, 44px); height: max(100%, 44px);
  transform: translate(-50%, -50%);
}
/* photo "remove" button: smaller bump so it can't swallow taps meant for the photo */
.photo-thumb .rm::after { content: ''; position: absolute; inset: -7px; }

/* === R3: premium polish — Apple-like surfaces, no layout change === */
:root {
  /* hairline ring + soft diffuse shadow (replaces the flatter default) */
  --shadow: 0 0 0 1px rgba(20,22,40,.04), 0 1px 2px rgba(20,22,40,.05), 0 10px 30px rgba(20,22,40,.06);
}
[data-theme="dark"] {
  --shadow: 0 0 0 1px rgba(255,255,255,.06), 0 1px 2px rgba(0,0,0,.5), 0 10px 30px rgba(0,0,0,.45);
}
body { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
/* numbers align like iOS — stats, totals, prices */
.stat-value, .co-total-val, .pos-bar-info strong, .prod-cost, .rt-grand, .cat-count, .pa-price, .cart-price, .co-price { font-variant-numeric: tabular-nums; }
/* real iOS glass: original bars had no -webkit- prefix, so iPhone Safari never blurred */
.topbar, .bottomnav, .pos-bar, .ai-live {
  -webkit-backdrop-filter: blur(18px) saturate(1.8);
  backdrop-filter: blur(18px) saturate(1.8);
}
.sheet { border-radius: 26px 26px 0 0; }
.btn-primary {
  background: linear-gradient(180deg, #5a52ee, var(--primary));
  box-shadow: 0 1px 2px rgba(79,70,229,.3), 0 4px 14px rgba(79,70,229,.22);
}
.btn-danger { box-shadow: 0 1px 2px rgba(220,38,38,.25), 0 4px 14px rgba(220,38,38,.18); }
.chip.active { box-shadow: 0 2px 10px rgba(79,70,229,.28); }
/* soft focus ring on all text fields */
.login-card input:focus, #add-form input:focus, #add-form select:focus,
.qform input:focus, .qform select:focus, .filter-grid select:focus, #prod-sort:focus,
.search-row input:focus, #login-pin:focus, .gate-input:focus, .pa-price:focus,
.cart-price:focus, .co-price:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3.5px rgba(79,70,229,.13);
}

/* === R3: dark-mode colour fixes (hard-coded light values) === */
[data-theme="dark"] .msg.ok, [data-theme="dark"] .scan-status.ok { background: rgba(22,163,74,.16); color: #4ade80; }
[data-theme="dark"] .msg.bad, [data-theme="dark"] .scan-status.bad, [data-theme="dark"] .qdup { background: rgba(220,38,38,.16); color: #fca5a5; }
[data-theme="dark"] .scan-status.work { background: rgba(99,102,241,.18); color: #a5b4fc; }
[data-theme="dark"] .badge.in, [data-theme="dark"] .badge.ready { background: rgba(22,163,74,.16); color: #4ade80; }
[data-theme="dark"] .badge.work { background: rgba(99,102,241,.18); color: #a5b4fc; }
[data-theme="dark"] .badge.wait { background: rgba(245,158,11,.18); color: #fbbf24; }
[data-theme="dark"] .staff-tag { background: rgba(99,102,241,.18); color: #a5b4fc; }
[data-theme="dark"] .pa-btn.move { background: rgba(99,102,241,.15); border-color: rgba(99,102,241,.35); color: #a5b4fc; }
[data-theme="dark"] .pa-btn.del { border-color: rgba(220,38,38,.35); color: #fca5a5; }
[data-theme="dark"] .btn-ghost.danger { background: rgba(220,38,38,.12); border-color: rgba(220,38,38,.3); color: #fca5a5; }
[data-theme="dark"] .btn-ghost.danger:active { background: rgba(220,38,38,.22); }
[data-theme="dark"] .recheck-pin { background: var(--card); }
[data-theme="dark"] .recheck-pin:hover { background: rgba(99,102,241,.18); }
[data-theme="dark"] .audit-act { background: rgba(99,102,241,.18); color: #a5b4fc; }
[data-theme="dark"] .audit-act.a-sell { background: rgba(22,163,74,.16); color: #4ade80; }
[data-theme="dark"] .audit-act.a-delete { background: rgba(220,38,38,.16); color: #fca5a5; }
[data-theme="dark"] .audit-act.a-edit { background: rgba(245,158,11,.18); color: #fbbf24; }
[data-theme="dark"] .photo-add { border-color: #3a3f52; }
[data-theme="dark"] .photo-add:active { background: rgba(99,102,241,.1); }
[data-theme="dark"] .sheet-handle { background: #3a3f52; }
[data-theme="dark"] .btn-ghost.small.icon { border-color: rgba(99,102,241,.35); color: #a5b4fc; }

/* === R2: readability — lift the smallest mobile font sizes === */
.mc-label { font-size: 11px; }
.ai-quota .aq-key { font-size: 11px; }
.prod-tags { font-size: 12px; }
.badge { font-size: 12px; }
.act-meta { font-size: 12px; }
.inst-rem { font-size: 12px; }
.mc-leg { font-size: 12px; }
.nav-btn { font-size: 12px; }

/* === R4: motion — soft & bouncy, never dizzy === */
/* springy press feedback for everything tappable that the base rules missed */
.chip, .cond-opt, .seg-btn, .scan-tool, .cart-rm, .icon-btn, .photo-add, .nav-btn .nav-ic, .d-thumb, .qthumbs img {
  transition: transform .42s var(--spring), background .15s ease;
}
.chip:active, .cond-opt:active, .seg-btn:active, .scan-tool:active, .cart-rm:active, .icon-btn:active, .photo-add:active {
  transform: scale(.93); transition: transform .08s ease-out;
}
.nav-btn:active .nav-ic { transform: scale(.82); transition: transform .08s ease-out; }
.d-thumb:active, .qthumbs img:active { transform: scale(.96); transition: transform .08s ease-out; }
.prod-top { transition: transform .42s var(--spring), opacity .2s ease; }
.prod-top:active { transform: scale(.985); transition: transform .08s ease-out, opacity .2s ease; }

/* scroll-reveal: cards drift up with a gentle spring as they enter the viewport
   (.rv added by app.js MutationObserver, .rv-in by IntersectionObserver) */
.rv { opacity: 0; transform: translateY(12px) scale(.99); }
.rv-in {
  opacity: 1; transform: none;
  transition: opacity .4s ease, transform .5s var(--spring);
  transition-delay: var(--rv-d, 0ms);
}

@media (prefers-reduced-motion: reduce) {
  .chip, .cond-opt, .seg-btn, .scan-tool, .cart-rm, .icon-btn, .photo-add, .nav-btn .nav-ic, .d-thumb, .qthumbs img, .prod-top { transition: background .15s ease; }
  .chip:active, .cond-opt:active, .seg-btn:active, .scan-tool:active, .cart-rm:active, .icon-btn:active, .photo-add:active,
  .nav-btn:active .nav-ic, .d-thumb:active, .qthumbs img:active, .prod-top:active { transform: none; }
  .rv { opacity: 1; transform: none; }
  .rv-in { transition: none; }
}

/* === R5: sliding active pill for segs / chips / toggles ===
   JS (app.js, presentation-only) adds .js-pill on <html>, measures the .active
   button and sets --pill-* on the container; this ::before glides under it.
   Without JS the original per-button active background still applies. */
.seg, .cond-toggle { position: relative; }
.seg::before, .cond-toggle::before {
  content: ''; position: absolute; z-index: 0;
  left: var(--pill-x, 0); top: var(--pill-y, 0);
  width: var(--pill-w, 0); height: var(--pill-h, 0);
  opacity: var(--pill-o, 0);
  border-radius: 9px; background: var(--card); box-shadow: var(--shadow);
  transition: left .32s var(--spring-soft), top .32s var(--spring-soft), width .32s var(--spring-soft), height .32s var(--spring-soft), opacity .15s ease;
}
[data-theme="dark"] .seg::before, [data-theme="dark"] .cond-toggle::before { background: #313647; }
.pill-noanim::before { transition: none !important; }
.seg-btn, .cond-opt { z-index: 1; }
/* hand the active background over to the pill (only when JS confirmed) */
.js-pill .seg-btn.active { background: transparent; box-shadow: none; }
.js-pill .cond-opt.active { background: transparent; box-shadow: none; }
[data-theme="dark"] .js-pill .seg-btn.active, [data-theme="dark"] .js-pill .cond-opt.active { background: transparent; }
/* chips are separate pills with gaps — a travelling blob shows in between,
   so they pop in place instead of sliding */
.chip.active { animation: chipPop .32s var(--spring-soft); }
@keyframes chipPop { from { transform: scale(.9); } to { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) {
  .seg::before, .cond-toggle::before { transition: none; }
  .chip.active { animation: none; }
}

/* desktop only: cards lift slightly under the pointer */
@media (hover: hover) and (pointer: fine) {
  .prod-card, .stat-card, .cat-row, .qcard {
    transition: transform .35s var(--spring), box-shadow .35s ease, opacity .4s ease;
  }
  .prod-card:hover, .stat-card:hover, .cat-row:hover, .qcard:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 0 1px rgba(20,22,40,.05), 0 2px 6px rgba(20,22,40,.06), 0 14px 36px rgba(20,22,40,.1);
  }
  .chip:hover { transform: translateY(-1px); }
  .btn-primary:hover { filter: brightness(1.06); }
  .btn-ghost:hover { background: var(--field); }
}

/* ---- "ขายแล้ว" sales log ---- */
.sold-day {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  margin: 18px 2px 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line);
}
.sold-day:first-child { margin-top: 4px; }
.sold-day-label { font-size: 14px; font-weight: 700; color: var(--ink); }
.sold-day-sum { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.sold-row .prod-right { align-items: flex-end; }
.sold-price { font-size: 15px; font-weight: 800; color: var(--green, #16a34a); white-space: nowrap; }
[data-theme="dark"] .sold-price { color: #4ade80; }
