/* ============================================================
   T-STONE Stock — แอปพนักงาน (มือถือเป็นหลัก, ใช้บนคอมได้)
   ธีม: สีทั้งหมดเป็นตัวแปรใน :root — โหมดมืดกำหนดใต้ [data-theme=dark]
   ============================================================ */
:root {
  --bg: #f6f6f3; --card: #ffffff; --ink: #15171c; --on-ink: #fff; --mute: #7a7f8a; --soft: #a4a8b1;
  --line: #e7e7e2; --line2: #d9d9d3; --chip: #f1f1ed; --soft-bg: #ecece8; --ph: #efefeb; --hover: #fafaf7; --nav-bg: #ffffff;
  --lime: #8cc63f; --lime-dk: #5f9b1f; --lime-bg: #eef7df;
  --mp: #f08a3e; --mp-bg: #fdeede; --ts: #2f6fde; --ts-bg: #e6eefb;
  --warn: #c98a00; --warn-bg: #fff4d6; --warn-ink: #6b4a00; --danger: #d64545; --danger-bg: #fbe5e5;
  --overlay: rgba(20,22,28,.45); --shadow: rgba(0,0,0,.2);
  --r: 14px; --nav-h: 64px; --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --font: "IBM Plex Sans Thai", -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
/* ---------- โหมดมืด ---------- */
:root[data-theme="dark"] {
  --bg: #14161a; --card: #1e2126; --ink: #ecedf0; --on-ink: #14161a; --mute: #9a9fab; --soft: #6b7079;
  --line: #2a2e35; --line2: #363b44; --chip: #272b31; --soft-bg: #2a2e35; --ph: #272b31; --hover: #23272d; --nav-bg: #1a1d22;
  --lime: #9cd44f; --lime-dk: #b5e36b; --lime-bg: #27371a;
  --mp: #f5a263; --mp-bg: #3d2a1a; --ts: #7fa6f0; --ts-bg: #1d2a44;
  --warn: #f0b640; --warn-bg: #3b3014; --warn-ink: #f3d79a; --danger: #ef6b6b; --danger-bg: #3d1f1f;
  --overlay: rgba(0,0,0,.6); --shadow: rgba(0,0,0,.5);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a; --card: #1e2126; --ink: #ecedf0; --on-ink: #14161a; --mute: #9a9fab; --soft: #6b7079;
    --line: #2a2e35; --line2: #363b44; --chip: #272b31; --soft-bg: #2a2e35; --ph: #272b31; --hover: #23272d; --nav-bg: #1a1d22;
    --lime: #9cd44f; --lime-dk: #b5e36b; --lime-bg: #27371a;
    --mp: #f5a263; --mp-bg: #3d2a1a; --ts: #7fa6f0; --ts-bg: #1d2a44;
    --warn: #f0b640; --warn-bg: #3b3014; --warn-ink: #f3d79a; --danger: #ef6b6b; --danger-bg: #3d1f1f;
    --overlay: rgba(0,0,0,.6); --shadow: rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.4; }
body { min-height: 100dvh; overscroll-behavior-y: contain; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 600; }
a { color: inherit; }
.mute { color: var(--mute); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }
.ellip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.app { max-width: 860px; margin: 0 auto; min-height: 100dvh; padding-bottom: calc(var(--nav-h) + var(--sab) + 90px); }
.splash { display: grid; place-items: center; height: 100dvh; }
.spin { width: 28px; height: 28px; border: 3px solid var(--line2); border-top-color: var(--lime); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- top bar ---------- */
.top { position: sticky; top: 0; z-index: 20; background: var(--bg); padding: calc(10px + var(--sat)) 16px 8px; }
.top .row { gap: 12px; }
.brand { font-weight: 700; letter-spacing: .5px; font-size: 18px; }
.brand b { color: var(--lime-dk); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--ink); color: var(--on-ink); display: grid; place-items: center; font-weight: 600; font-size: 14px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-top: 10px; }
.search input { flex: 1; border: 0; outline: 0; background: none; font-size: 16px; }
.search svg { width: 18px; height: 18px; color: var(--soft); flex: none; }
.search .clr { color: var(--soft); font-size: 20px; line-height: 1; padding: 0 2px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px 6px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line2); background: var(--card); border-radius: 999px; padding: 6px 14px; font-size: 14px; color: var(--mute); white-space: nowrap; }
.chip.on { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.seg { display: inline-flex; background: var(--soft-bg); border-radius: 10px; padding: 3px; }
.seg button { padding: 6px 12px; border-radius: 8px; font-size: 13px; color: var(--mute); font-weight: 500; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- lists ---------- */
.list { padding: 4px 16px; display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 10px; text-align: left; width: 100%; }
.item:active { background: var(--hover); }
/* สไลด์ซ้าย → แก้ไข / ลบ */
.swipe { position: relative; border-radius: var(--r); overflow: hidden; }
.swipe-actions { position: absolute; top: 0; bottom: 0; right: 0; display: flex; }
.swipe-actions button { width: 75px; color: #fff; font-weight: 600; font-size: 14px; }
.swipe-actions .ed { background: #15171c; } .swipe-actions .del { background: #d64545; }
:root[data-theme="dark"] .swipe-actions .ed { background: #363b44; }
.swipe .item { position: relative; z-index: 1; transition: transform .22s cubic-bezier(.2,.8,.2,1); touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.swipe .item.drag { transition: none; }
.swipe.open .item { transform: translateX(-150px); }
.swipe .item img { pointer-events: none; -webkit-user-drag: none; }
.thumb { width: 60px; height: 60px; border-radius: 10px; background: var(--ph); object-fit: cover; flex: none; display: grid; place-items: center; color: var(--soft); overflow: hidden; }
.thumb svg { width: 26px; height: 26px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.item .name { font-weight: 600; font-size: 15px; }
.item .sub { font-size: 12px; color: var(--mute); margin-top: 1px; }
.item .qty { text-align: right; flex: none; }
.item .qty b { font-size: 20px; font-weight: 700; display: block; line-height: 1.1; }
.item .qty span { font-size: 11px; color: var(--mute); }
.locs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.loc { font-size: 11px; background: var(--chip); border-radius: 6px; padding: 2px 7px; color: var(--mute); }
.loc b { color: var(--ink); font-weight: 600; }
.loc.held { background: var(--lime-bg); color: var(--lime-dk); }
.loc.res { background: var(--warn-bg); color: var(--warn); }
.tag { font-size: 11px; border-radius: 6px; padding: 1px 6px; font-weight: 600; }
.tag.c-tstone { background: var(--ts-bg); color: var(--ts); }
.tag.c-mp { background: var(--mp-bg); color: var(--mp); }
.tag.ok { background: var(--lime-bg); color: var(--lime-dk); }
.empty { text-align: center; color: var(--mute); padding: 40px 20px; }
.empty svg { width: 44px; height: 44px; color: var(--line2); margin-bottom: 8px; }

/* ---------- bottom nav ---------- */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--nav-bg); border-top: 1px solid var(--line); padding-bottom: var(--sab); }
.nav .in { max-width: 860px; margin: 0 auto; display: flex; height: var(--nav-h); }
.nav button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--mute); font-weight: 500; position: relative; }
.nav button svg { width: 24px; height: 24px; }
.nav button.on { color: var(--ink); }
.nav button.on svg { color: var(--lime-dk); }
.nav .badge { position: absolute; top: 8px; left: calc(50% + 6px); min-width: 18px; height: 18px; border-radius: 9px; background: var(--lime); color: #14161a; font-size: 11px; display: grid; place-items: center; padding: 0 5px; }
.nav .badge.warn { background: var(--danger); color: #fff; }
body.sheet-open .nav, body.sheet-open .cartpill { visibility: hidden; }

/* ---------- cart pill ---------- */
.cartpill { position: fixed; z-index: 29; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--sab) + 12px); background: var(--ink); color: var(--on-ink); border-radius: 999px; padding: 12px 20px; font-weight: 600; display: flex; gap: 10px; align-items: center; white-space: nowrap; box-shadow: 0 8px 24px var(--shadow); }
.cartpill svg { width: 20px; height: 20px; flex: none; }
.cartpill .n { background: var(--lime); color: #14161a; border-radius: 999px; padding: 0 9px; font-size: 13px; line-height: 22px; }

/* ---------- sheet ---------- */
.sheet-bg { position: fixed; inset: 0; z-index: 50; background: var(--overlay); display: flex; align-items: flex-end; justify-content: center; animation: fade .18s; }
.sheet { background: var(--card); width: 100%; max-width: 680px; max-height: 92dvh; border-radius: 20px 20px 0 0; overflow: auto; padding: 8px 18px calc(22px + var(--sab)); animation: up .22s cubic-bezier(.2,.8,.2,1); }
.sheet .grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line2); margin: 4px auto 14px; }
.sheet h2 { font-size: 18px; margin-bottom: 4px; }
.sheet .hero { width: 100%; aspect-ratio: 4/3; border-radius: 14px; background: var(--ph); object-fit: cover; margin: 6px 0 12px; display: grid; place-items: center; color: var(--soft); overflow: hidden; }
.sheet .hero img { width: 100%; height: 100%; object-fit: cover; }
.sheet .hero svg { width: 48px; height: 48px; }
.sec { font-size: 12px; color: var(--mute); text-transform: uppercase; letter-spacing: .6px; margin: 18px 0 8px; font-weight: 600; }
.line { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.line .n { font-weight: 600; }
.line .d { font-size: 12px; color: var(--mute); }
.line .step { flex: none; } .line .step button { width: 34px; height: 36px; font-size: 18px; } .line .step input { width: 44px; height: 36px; font-size: 15px; }
.line .thumb { width: 48px; height: 48px; }
.big { font-size: 22px; font-weight: 700; }
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-top: 16px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
@media (min-width: 720px) {
  .sheet-bg { align-items: center; padding: 20px; }
  .sheet { border-radius: 20px; max-height: 88vh; }
}

/* ---------- buttons / forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 12px 16px; border-radius: 12px; font-weight: 600; font-size: 15px; background: var(--soft-bg); color: var(--ink); border: 1px solid transparent; }
.btn.pri { background: var(--lime); color: #14161a; }
.btn.dark { background: var(--ink); color: var(--on-ink); }
.btn.ghost { background: transparent; border-color: var(--line2); }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn.xs { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.field { margin: 10px 0; }
.field label { display: block; font-size: 13px; color: var(--mute); margin-bottom: 5px; font-weight: 500; }
.field input, .field select, .field textarea { width: 100%; background: var(--card); border: 1px solid var(--line2); border-radius: 12px; padding: 11px 12px; outline: 0; font-size: 16px; color: var(--ink); }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--ink); }
.field textarea { min-height: 70px; resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.step { display: inline-flex; align-items: center; border: 1px solid var(--line2); border-radius: 12px; overflow: hidden; background: var(--card); }
.step button { width: 42px; height: 42px; font-size: 20px; font-weight: 600; color: var(--ink); background: var(--soft-bg); }
.step input { width: 58px; height: 42px; text-align: center; border: 0; outline: 0; font-size: 17px; font-weight: 600; -moz-appearance: textfield; background: var(--card); color: var(--ink); }
.step input::-webkit-outer-spin-button, .step input::-webkit-inner-spin-button { -webkit-appearance: none; }
.note { background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin: 8px 0; }
.note b { color: var(--warn); }
.ok { background: var(--lime-bg); color: var(--lime-dk); }
.err { color: var(--danger); font-size: 13px; margin-top: 6px; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login .card { width: 100%; max-width: 380px; background: var(--card); border-radius: 22px; padding: 28px 24px; border: 1px solid var(--line); }
.login .logo { width: 56px; height: 56px; border-radius: 16px; margin-bottom: 14px; }
.login h1 { font-size: 24px; }
.login p { color: var(--mute); margin: 4px 0 18px; }

/* ---------- boxes (ของกับฉัน) ---------- */
.people { display: flex; gap: 8px; overflow-x: auto; padding: 8px 16px; scrollbar-width: none; }
.people::-webkit-scrollbar { display: none; }
.boxes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 8px 16px; }
@media (min-width: 560px) { .boxes { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 820px) { .boxes { grid-template-columns: repeat(4, 1fr); } }
.box { position: relative; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px; overflow: hidden; }
.box.closed { opacity: .55; }
.box .carton { position: relative; height: 92px; margin: 2px 0 10px; }
.box .carton .flap { position: absolute; inset: auto 0 0 0; height: 58px; background: linear-gradient(#e8c58e, #d4ab6c); border-radius: 6px; border: 1px solid #c79a57; }
.box .carton .flap:before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 10px; margin-left: -5px; background: rgba(255,255,255,.35); }
.box .carton .flap:after { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 8px; background: #c79a57; opacity: .5; }
.box .stack { position: absolute; left: 10px; right: 10px; bottom: 34px; height: 60px; }
.box .stack .ph { position: absolute; bottom: 0; width: 48px; height: 48px; border-radius: 8px; background: var(--ph); border: 2px solid var(--card); box-shadow: 0 2px 6px var(--shadow); overflow: hidden; display: grid; place-items: center; color: var(--soft); }
.box .stack .ph img { width: 100%; height: 100%; object-fit: cover; }
.box .stack .ph svg { width: 22px; height: 22px; }
.box .stack .more { background: var(--ink); color: var(--on-ink); font-size: 12px; font-weight: 700; }
.box .when { font-size: 12px; color: var(--mute); }
.box .place { font-weight: 600; font-size: 14px; margin-top: 2px; }
.box .cnt { font-size: 12px; color: var(--mute); margin-top: 2px; }
.box .owner { position: absolute; top: 10px; right: 10px; }

/* ---------- add item form ---------- */
.page { padding: 8px 16px; }
.page h1 { font-size: 22px; margin: 8px 0 12px; }
.photo-pick { width: 100%; aspect-ratio: 16/10; border: 2px dashed var(--line2); border-radius: 16px; display: grid; place-items: center; color: var(--mute); background: var(--card); overflow: hidden; position: relative; }
.photo-pick img { width: 100%; height: 100%; object-fit: cover; }
.photo-pick .hint { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 14px; }
.photo-pick .hint svg { width: 34px; height: 34px; }
.photo-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-pick .upstat { position: absolute; left: 10px; right: 10px; bottom: 10px; background: rgba(21,23,28,.78); color: #fff; font-size: 13px; padding: 6px 10px; border-radius: 8px; text-align: center; pointer-events: none; }
.stockrow { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.stockrow select { flex: 1; background: var(--card); color: var(--ink); border: 1px solid var(--line2); border-radius: 12px; padding: 10px; font-size: 16px; }
.stockrow .step { flex: none; }
.stockrow .x { color: var(--soft); font-size: 20px; width: 30px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin: 10px 0; }
.card h3 { font-size: 15px; margin-bottom: 8px; }
.card .inp { background: var(--card); color: var(--ink); border: 1px solid var(--line2); border-radius: 10px; padding: 8px 10px; }
.kv { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv:last-child { border-bottom: 0; }

/* ---------- toast ---------- */
.toast { position: fixed; z-index: 99; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--sab) + 70px); background: var(--ink); color: var(--on-ink); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; box-shadow: 0 8px 24px var(--shadow); }
.toast.bad { background: var(--danger); color: #fff; }

@media (min-width: 720px) {
  .top { padding-top: 16px; }
  .list { gap: 10px; }
}
