:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #17201e;
  --muted: #5d6b68;
  --border: #dbe2e0;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #d9f0ec;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --warn: #9a5b00;
  --warn-soft: #fff1d6;
  --ok: #1b7a3e;
  --ok-soft: #dcf3e4;
  --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 4px 16px rgba(16, 24, 22, .06);
  --radius: 14px;
  --gutter: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1413;
    --surface: #171e1c;
    --surface-2: #1f2826;
    --text: #e6eeec;
    --muted: #9aaaa6;
    --border: #2b3633;
    --primary: #2dd4bf;
    --primary-ink: #04201c;
    --primary-soft: #133a35;
    --danger: #f97066;
    --danger-soft: #3a1714;
    --warn: #fdb022;
    --warn-soft: #3a2a0b;
    --ok: #47cd89;
    --ok-soft: #0f2e1d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1413; --surface: #171e1c; --surface-2: #1f2826; --text: #e6eeec; --muted: #9aaaa6;
  --border: #2b3633; --primary: #2dd4bf; --primary-ink: #04201c; --primary-soft: #133a35;
  --danger: #f97066; --danger-soft: #3a1714; --warn: #fdb022; --warn-soft: #3a2a0b;
  --ok: #47cd89; --ok-soft: #0f2e1d; --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px var(--gutter);
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  background: var(--primary); color: var(--primary-ink);
}
.badge-beta {
  font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 99px;
  background: var(--warn-soft); color: var(--warn);
}
.topbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-name { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }

.app { max-width: 960px; margin: 0 auto; padding: 16px var(--gutter) 96px; }

/* ---------- buttons / inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { filter: brightness(1.05); background: var(--primary); }
.btn-danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn-block { width: 100%; }

.field { display: grid; gap: 6px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 500; }
.input, .textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 11px; background: var(--surface);
  font-size: 16px; /* no iOS zoom */
}
.textarea { min-height: 80px; resize: vertical; }
.input:focus, .textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }

/* ---------- login ---------- */
.login-wrap { min-height: 80vh; display: grid; place-items: center; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px 22px; box-shadow: var(--shadow); display: grid; gap: 16px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; color: var(--muted); font-size: 14px; }
.form-error { color: var(--danger); background: var(--danger-soft); padding: 10px 12px; border-radius: 10px; font-size: 14px; }

/* ---------- list ---------- */
.search-row { display: grid; gap: 10px; position: sticky; top: 58px; z-index: 10; background: var(--bg); padding: 4px 0 10px; }
.search-box { position: relative; }
.search-box svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-box .input { padding-left: 40px; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chip {
  flex: 0 0 auto; min-height: 34px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-size: 14px; font-weight: 500;
}
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.list-meta { color: var(--muted); font-size: 13px; margin: 4px 2px 10px; }

.search-line { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.photo-search-btn { padding: 0 12px; gap: 6px; }
@media (max-width: 340px) { .photo-search-btn span { display: none; } .photo-search-btn { width: 46px; padding: 0; } }

.ai-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); display: grid; gap: 10px; margin: 4px 0 12px; scroll-margin-top: 150px; }
.ai-panel:empty { display: none; }
.ai-row { display: grid; grid-template-columns: 56px 1fr; gap: 12px; align-items: center; }
.ai-thumb { width: 56px; height: 56px; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.ai-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ai-q { font-size: 16px; font-weight: 600; }
.ai-q .ai-hint { font-weight: 400; margin-left: 4px; }
.ai-why { font-size: 13px; color: var(--muted); line-height: 1.45; padding: 0 4px; }
.ai-more summary { cursor: pointer; font-size: 13px; color: var(--primary); font-weight: 600; padding: 4px 0; }
.ai-more[open] { display: grid; gap: 8px; }
.ai-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ai-foot .btn-ghost { margin-left: auto; }
.ai-engine { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.ai-engine select { min-height: 36px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); padding: 0 8px; font-size: 14px; color: var(--text); }
.result-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; font-weight: 700; font-size: 15px; margin: 2px 2px 10px; }
.result-head span { font-weight: 400; font-size: 13px; color: var(--muted); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--surface-2); border-radius: 11px; padding: 4px; }
.seg button { min-height: 36px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); padding: 0 6px; }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.ai-hint { margin: 0; color: var(--muted); font-size: 12px; }
.ai-body { display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: start; }
.ai-preview { width: 96px; height: 96px; border-radius: 10px; background: var(--surface-2); overflow: hidden; display: grid; place-items: center; color: var(--muted); font-size: 12px; text-align: center; }
.ai-preview img { width: 100%; height: 100%; object-fit: cover; }
.ai-side { display: grid; gap: 8px; min-width: 0; }
.ai-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ai-status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.ai-type { font-weight: 600; font-size: 14px; }
.ai-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-chips .chip { min-height: 30px; font-size: 13px; padding: 0 10px; }
.ai-text { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.ai-label { font-size: 12px; font-weight: 600; color: var(--muted); margin-top: 2px; }
.cands { display: grid; gap: 6px; }
.cand {
  display: grid; grid-template-columns: 18px 1fr auto; gap: 10px; align-items: center; text-align: left;
  min-height: 52px; padding: 8px 12px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface);
}
.cand[aria-checked="true"] { border: 2px solid var(--primary); background: var(--primary-soft); padding: 7px 11px; }
.cand-dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border); }
.cand[aria-checked="true"] .cand-dot { border: 5px solid var(--primary); }
.cand-main { display: grid; min-width: 0; font-size: 15px; line-height: 1.3; }
.cand-en { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cand-side { display: grid; justify-items: end; gap: 1px; }
.cand-pct { font-size: 12px; font-weight: 600; color: var(--primary); }
.cand-count { font-size: 12px; color: var(--muted); white-space: nowrap; }
.ai-tip { font-size: 13px; padding: 8px 10px; border-radius: 10px; background: var(--warn-soft); color: var(--text); }

.pending-photo { display: grid; grid-template-columns: 48px 1fr auto auto; gap: 10px; align-items: center; margin-top: 10px; padding: 8px; border-radius: 11px; background: var(--primary-soft); font-size: 14px; }
.pending-photo img { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; }

.item-list { display: grid; gap: 10px; }
.item-card {
  display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: center;
  padding: 10px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border);
  text-decoration: none; box-shadow: var(--shadow);
}
.item-card:active { transform: scale(.995); }
.thumb {
  width: 64px; height: 64px; border-radius: 10px; background: var(--surface-2); overflow: hidden;
  display: grid; place-items: center; color: var(--muted);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-card-body { min-width: 0; }
.item-num { font-weight: 700; font-size: 15px; }
.item-desc { color: var(--muted); font-size: 13px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item-stats { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 4px; font-size: 13px; }
.item-stats b { font-weight: 600; }
.pill { font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }

.empty, .loading { text-align: center; color: var(--muted); padding: 40px 12px; }
.spinner {
  width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin .8s linear infinite; display: inline-block; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- item page ---------- */
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none; font-size: 14px; margin-bottom: 10px; }
.item-head h1 { margin: 0; font-size: 22px; line-height: 1.25; }
.item-head .desc { color: var(--muted); margin: 4px 0 0; }
.item-head .sub { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.item-grid { display: grid; gap: 14px; margin-top: 14px; }
@media (min-width: 760px) {
  .item-grid { grid-template-columns: 340px 1fr; align-items: start; }
  .item-grid .col-photos { position: sticky; top: 74px; }
}

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 10px; font-size: 16px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-title h2 { margin: 0; }

.photo-main {
  aspect-ratio: 4 / 3; border-radius: 12px; overflow: hidden; background: var(--surface-2);
  display: grid; place-items: center; color: var(--muted); cursor: zoom-in;
}
.photo-main img { width: 100%; height: 100%; object-fit: cover; }
.photo-main.empty-photo { cursor: default; text-align: center; padding: 16px; font-size: 14px; }
.photo-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; margin-top: 10px; }
.photo-strip button {
  position: relative; aspect-ratio: 1; padding: 0; border: 2px solid transparent; border-radius: 10px;
  overflow: hidden; background: var(--surface-2); cursor: pointer;
}
.photo-strip button.is-primary { border-color: var(--primary); }
.photo-strip img { width: 100%; height: 100%; object-fit: cover; }
.photo-strip .star {
  position: absolute; top: 3px; left: 3px; font-size: 10px; font-weight: 700; padding: 0 5px; border-radius: 6px;
  background: var(--primary); color: var(--primary-ink);
}
.photo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.upload-queue { display: grid; gap: 6px; margin-top: 10px; }
.upload-row { display: flex; align-items: center; gap: 10px; font-size: 13px; padding: 6px 8px; border-radius: 9px; background: var(--surface-2); }
.upload-row img { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; }
.upload-row .status { margin-left: auto; color: var(--muted); }
.upload-row.ok .status { color: var(--ok); }
.upload-row.err .status { color: var(--danger); }
.hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.compare { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.stat { background: var(--surface-2); border-radius: 11px; padding: 10px; min-width: 0; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 20px; font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.stat .unit { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat.app { background: var(--primary-soft); }
.stat.diff-bad .value { color: var(--danger); }
.compare-2 { grid-template-columns: 1fr 1fr; margin-top: 8px; }
.stat .value.sm { font-size: 16px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

.form-grid { display: grid; gap: 12px; margin-top: 12px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.save-row { display: flex; align-items: center; gap: 10px; }
.save-row .hint { color: var(--muted); font-size: 13px; }

details.store-table summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; }
details.store-table summary::-webkit-details-marker { display: none; }
.table-wrap { overflow-x: auto; margin-top: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.history li { display: grid; grid-template-columns: 26px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.history li:last-child { border-bottom: 0; }
.h-icon { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.h-app { background: var(--primary-soft); color: var(--primary); }
.h-mx { background: var(--surface-2); color: var(--muted); }
.h-time { color: var(--muted); font-size: 12px; }

/* ---------- system status page ---------- */
@media (max-width: 480px) { .hide-sm { display: none; } }
.admin-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.admin-head h1 { margin: 0; font-size: 22px; }
.admin-meta { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.st-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
@media (max-width: 480px) { .st-grid { grid-template-columns: 1fr 1fr; } .st-label { font-size: 16px; } }
.st-tile { background: var(--surface); border: 1px solid var(--border); border-left-width: 5px; border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.st-good { border-left-color: var(--ok); } .st-warning { border-left-color: var(--warn); } .st-critical { border-left-color: var(--danger); }
.st-top { display: flex; align-items: center; gap: 8px; }
.st-icon { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff; flex: 0 0 auto; }
.st-good .st-icon { background: var(--ok); } .st-warning .st-icon { background: var(--warn); } .st-critical .st-icon { background: var(--danger); }
.st-title { font-size: 13px; color: var(--muted); font-weight: 500; }
.st-label { font-size: 18px; font-weight: 700; margin-top: 6px; }
.st-detail { font-size: 13px; color: var(--muted); }

.card.adm { margin-bottom: 14px; display: grid; gap: 12px; }
.card.adm h2 { margin: 0; }
.card.adm h3 { margin: 4px 0 0; font-size: 14px; color: var(--muted); font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.kpi { background: var(--surface-2); border-radius: 11px; padding: 10px 12px; min-width: 0; }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 20px; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.kpi-sub { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.badge { font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 99px; white-space: nowrap; }
.b-good { background: var(--ok-soft); color: var(--ok); } .b-warning { background: var(--warn-soft); color: var(--warn); } .b-critical { background: var(--danger-soft); color: var(--danger); }
td.msg { color: var(--muted); max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.meter-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.meter { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.meter-fill { display: block; height: 100%; border-radius: 99px; }
.m-good { background: var(--ok); } .m-warning { background: var(--warn); } .m-critical { background: var(--danger); }

.chart-wrap { position: relative; }
svg.bars { width: 100%; height: auto; display: block; }
svg.bars .bar-fill { fill: var(--primary); }
svg.bars .bar.on .bar-fill { opacity: .75; }
svg.bars .hit { fill: transparent; }
svg.bars .grid { stroke: var(--border); stroke-dasharray: 3 3; }
svg.bars .axis { stroke: var(--border); }
svg.bars .tick { font-size: 10px; fill: var(--muted); }
.chart-tip { position: absolute; top: 0; transform: translateX(-50%); background: var(--text); color: var(--bg); font-size: 12px; padding: 3px 8px; border-radius: 6px; pointer-events: none; white-space: nowrap; }
.table-view summary { cursor: pointer; font-size: 13px; color: var(--primary); }
.adm-2col { display: grid; gap: 14px; }
@media (min-width: 680px) { .adm-2col { grid-template-columns: 1fr 1.4fr; } }
.rank { margin: 6px 0 0; padding-left: 20px; display: grid; gap: 4px; font-size: 14px; }
.rank li span { display: inline-block; min-width: 60%; }
.recent { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; margin-top: 6px; }
.recent a { aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.recent img { width: 100%; height: 100%; object-fit: cover; }
.maint { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.links { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 14px; }
.links a { color: var(--primary); }

/* ---------- one-screen dashboard (overrides the stacked layout above) ---------- */
.app.wide { max-width: 1480px; padding-top: 10px; padding-bottom: 8px; }
.dash { display: grid; gap: 10px; }
.dash-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.dash-head h1 { margin: 0; font-size: 20px; }
.dash-head .admin-meta { margin-right: auto; }
.dash .st-grid { margin: 0; gap: 8px; }
.dash .st-tile { padding: 8px 12px; display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: center; }
.dash .st-top { display: contents; }
.dash .st-icon { grid-row: span 2; width: 26px; height: 26px; font-size: 14px; }
.dash .st-title { grid-column: 2; }
.dash .st-label { display: none; }
.dash .st-detail { grid-column: 2; color: var(--text); font-weight: 600; font-size: 14px; }
.dash-cols { display: grid; gap: 10px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); display: grid; gap: 8px; align-content: start; min-width: 0; }
.panel h2 { margin: 0; font-size: 15px; }
.panel h2.mt { margin-top: 4px; }
.panel h3 { margin: 0; font-size: 12px; color: var(--muted); font-weight: 600; }
.info { color: var(--muted); font-size: 12px; cursor: help; }
.kpis.k2 { grid-template-columns: 1fr 1fr; gap: 6px; }
.panel .kpi { padding: 7px 10px; }
.panel .kpi-value { font-size: 17px; }
.panel .kpi-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
table.compact th, table.compact td { padding: 4px 6px; font-size: 12px; }
table.compact td.msg { max-width: 110px; }
.panel .chart-wrap svg.bars { max-height: 96px; }
.panel .table-view summary { font-size: 12px; }
.panel .kpi-label { font-size: 11px; }
.photo-foot { display: grid; gap: 6px; }
.panel .recent { grid-template-columns: repeat(8, 1fr); margin: 0; gap: 4px; }
.uploaders { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); }
.uploaders b { color: var(--text); }
.tbl-sizes { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12px; color: var(--muted); }
.tbl-sizes b { color: var(--text); font-weight: 600; }
.mini-stats { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; }
.mini-stats small { color: var(--muted); }
.panel .maint { font-size: 13px; }
.maint-checks { display: flex; flex-wrap: wrap; gap: 6px; }
.maint-checks .badge { cursor: help; }
.panel .links { font-size: 13px; gap: 4px 12px; }
@media (min-width: 1000px) {
  .dash-cols { grid-template-columns: 1fr 1.15fr 1fr; }
  .dash .st-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 999px) and (min-width: 640px) {
  .dash-cols { grid-template-columns: 1fr 1fr; }
  .dash-cols .panel:last-child { grid-column: 1 / -1; }
}

/* ---------- Thai names ---------- */
.item-th { font-weight: 600; color: var(--primary); margin-left: 6px; font-size: 14px; }
.pill-cat { background: var(--primary-soft); color: var(--primary); }
.name-th { margin: 2px 0 0; font-size: 17px; }
.name-th.uncertain { font-size: 14px; color: var(--muted); }

/* ---------- counting per storeroom x bin ---------- */
.sr-block { border: 1px solid var(--border); border-radius: 12px; padding: 10px; display: grid; gap: 8px; }
.sr-block + .sr-block { margin-top: 8px; }
.sr-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px 10px; font-size: 14px; }
.sr-nums { color: var(--muted); font-size: 13px; display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sr-nums b { color: var(--text); }
.cnt-row { display: grid; grid-template-columns: minmax(70px, 1fr) 90px auto auto auto; gap: 6px; align-items: center; }
.cnt-row .input { min-height: 40px; padding: 6px 10px; }
.cnt-bin { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.cnt-unit { font-size: 12px; color: var(--muted); }
.cnt-time { grid-column: 1 / -1; margin-top: -4px; }
.cnt-new { grid-template-columns: minmax(70px, 1fr) 90px auto auto; padding-top: 6px; border-top: 1px dashed var(--border); }
.note-field { margin-top: 12px; }

/* ---------- background upload badge ---------- */
.upload-badge { background: var(--primary-soft); border-color: transparent; color: var(--primary); gap: 6px; }
.upload-badge.has-error { background: var(--danger-soft); color: var(--danger); }
.spinner.sm { width: 14px; height: 14px; border-width: 2px; }

/* ---------- toast / lightbox ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 50;
  max-width: calc(100vw - 32px); box-shadow: var(--shadow);
}
.toast.err { background: var(--danger); color: #fff; }

.lightbox { border: 0; padding: 0; background: transparent; max-width: 100vw; max-height: 100vh; width: 100%; }
.lightbox::backdrop { background: rgba(0, 0, 0, .82); }
.lightbox-inner { display: grid; gap: 10px; justify-items: center; padding: 12px; }
.lightbox img { max-height: 72vh; width: auto; border-radius: 10px; background: #222; }
.lightbox-meta { color: #ddd; font-size: 13px; text-align: center; }
.lightbox-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.lightbox .btn-ghost { color: #fff; }
table.ai-usage td:last-child { min-width: 90px; }
table.ai-usage .meter { min-width: 70px; }
.panel .hint { font-size: 11px; color: var(--muted); }
@media (min-width: 1000px) { .dash .st-grid { grid-template-columns: repeat(5, 1fr); } }

/* ---------- side tabs (desktop) / bottom tab bar (mobile) ---------- */
.page-head { margin: 2px 2px 10px; }
.page-head h1 { margin: 0; font-size: 20px; }
.page-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.item-head-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.manage-cta { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.sidenav { position: fixed; z-index: 15; background: var(--surface); }
.sidenav[hidden] { display: none; }
.sidenav a {
  display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--muted);
  font-weight: 600; font-size: 15px; border-radius: 11px;
}
.sidenav a:hover { color: var(--text); background: var(--surface-2); }
.sidenav a[aria-current="page"] { color: var(--primary); background: var(--primary-soft); }

@media (min-width: 760px) {
  .sidenav {
    top: 58px; left: 0; bottom: 0; width: 200px; padding: 14px 10px;
    border-right: 1px solid var(--border); display: grid; align-content: start; gap: 4px;
  }
  .sidenav a { padding: 11px 14px; }
  body.has-nav .app { margin-left: 200px; }
  body.has-nav .app:not(.wide) { margin-left: max(200px, calc((100vw - 960px) / 2 + 100px)); }
}
@media (max-width: 759px) {
  .sidenav {
    left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: 1fr 1fr;
    border-top: 1px solid var(--border); padding: 6px 8px max(6px, env(safe-area-inset-bottom));
  }
  .sidenav a { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 12px; justify-content: center; }
  body.has-nav .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
}
@media (max-width: 759px) { #themeBtn span { display: none; } }
.brand { white-space: nowrap; }

/* ---------- Stock tab: scope filter + summary cards ---------- */
.stock-scope { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) auto; gap: 10px; align-items: end; margin-bottom: 10px; }
.stock-scope[hidden] { display: none; }
.stock-scope .field { display: grid; gap: 4px; margin: 0; }
.stock-scope label { font-size: 13px; color: var(--muted); font-weight: 500; }
.stock-scope select.input { appearance: auto; }
@media (max-width: 520px) { .stock-scope { grid-template-columns: 1fr 1fr; } .stock-scope #scopeClear { grid-column: 1 / -1; } }

.sum-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; transition: opacity .15s; }
.sum-grid.is-loading { opacity: .55; }
.sum-grid:empty { min-height: 120px; background: var(--surface-2); border-radius: var(--radius); }
.sum-scope { grid-column: 1 / -1; font-size: 13px; color: var(--muted); margin: 0 2px; }
.sum-scope b { color: var(--text); }
.sum-tile {
  text-align: left; font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); display: grid; gap: 2px; align-content: start; min-width: 0;
}
button.sum-tile { cursor: pointer; }
button.sum-tile:hover { border-color: var(--primary); }
.sum-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.sum-value { font-size: 20px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.sum-value small { font-size: 13px; color: var(--muted); font-weight: 500; }
.sum-sub { font-size: 12px; color: var(--muted); }
.sum-tile.is-warn { border-color: var(--warn); background: var(--warn-soft); }
.sum-tile.is-warn .sum-value { color: var(--warn); }
.sum-progress { grid-column: span 2; }
.sum-progress .bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 4px 0 2px; }
.sum-progress .bar span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.sum-missing { grid-column: 1 / -1; padding: 12px; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--muted); font-size: 13px; }
@media (max-width: 640px) { .sum-grid { grid-template-columns: 1fr 1fr; } .sum-value { font-size: 18px; } }
@media (max-width: 520px) {
  .stock-scope { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; }
  .stock-scope #scopeClear { grid-column: auto; padding: 0 12px; }
  .stock-scope label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sum-tile:not(.sum-progress) .sum-sub { display: none; }
  .sum-tile { padding: 8px 10px; }
  .user-name { display: none; }
}
@media (max-width: 420px) {
  .topbar { gap: 6px; }
  .topbar-right { gap: 2px; }
  .topbar-right .btn-sm { padding: 0 8px; }
  .badge-beta { display: none; }
}

/* ---------- item page: title, photo size, product info, per-store list ---------- */
.item-title { margin: 0; font-size: 22px; line-height: 1.3; font-weight: 400; min-width: 0; flex: 1 1 260px; }
.item-title-num { font-weight: 700; color: var(--text); margin-right: 4px; }
.item-title-desc { font-size: 14.5px; color: var(--muted); font-weight: 400; overflow-wrap: anywhere; }
@media (max-width: 759px) {
  .photo-main { aspect-ratio: auto; height: min(34vh, 260px); }
  .photo-main img { object-fit: contain; }
  .photo-main.empty-photo { height: auto; min-height: 96px; }
}

.pi-meta, .pi-minor { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.pi-meta div, .pi-minor div { min-width: 0; }
.pi-meta dt, .pi-minor dt { font-size: 12.5px; color: var(--muted); }
.pi-meta dd { margin: 0; font-weight: 600; font-size: 15px; }
.pi-meta dd small { font-weight: 400; color: var(--muted); font-size: 12px; }
.pi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.pi-box { background: var(--surface-2); border-radius: 11px; padding: 10px 12px; display: grid; gap: 1px; min-width: 0; }
.pi-box.pi-main { background: var(--primary-soft); }
.pi-box.pi-main.is-diff { background: var(--warn-soft); }
.pi-label { font-size: 12px; color: var(--muted); }
.pi-label + .pi-label, .pi-value + .pi-label, .pi-src + .pi-label { margin-top: 6px; }
.pi-value { font-size: 22px; font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.pi-value small { font-size: 12px; color: var(--muted); font-weight: 500; }
.pi-money { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.pi-src { font-size: 11.5px; color: var(--muted); }
.pi-minor { border-top: 1px dashed var(--border); padding-top: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.pi-minor dd { margin: 0; font-size: 14px; color: var(--muted); }   /* ตัวอักษรอ่อน ตามที่ขอ */
.pi-minor dd.neg { color: var(--danger); } .pi-minor dd.pos { color: var(--ok); }
@media (max-width: 480px) { .pi-minor { grid-template-columns: 1fr 1fr; } .pi-value { font-size: 20px; } }

.st-list { display: grid; }
.st-row { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 2px; border-bottom: 1px solid var(--border); font-size: 14px; }
.st-headrow { font-size: 12px; color: var(--muted); padding-top: 0; }
.st-name { font-weight: 600; overflow-wrap: anywhere; }
.st-name small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.st-old { color: var(--muted); overflow-wrap: anywhere; }
.st-bal { font-weight: 700; font-size: 16px; text-align: right; white-space: nowrap; }
.st-bal.zero { color: var(--muted); font-weight: 500; }
.st-headrow .num { text-align: right; }
.st-total { border-bottom: 0; font-weight: 600; }
.st-total .st-bal small { font-weight: 500; color: var(--muted); font-size: 12px; }

/* ---------- per-store table (collapsed by default) ---------- */
details.store-table summary { align-items: center; gap: 10px; }
details.store-table summary > span:first-child { display: inline-flex; align-items: center; gap: 8px; }
details.store-table summary::before { content: "▸"; color: var(--muted); margin-right: -2px; transition: transform .15s; }
details.store-table[open] summary::before { transform: rotate(90deg); }
details.store-table summary > span:first-child { margin-right: auto; }
.st-table { font-size: 14px; }
.st-table th { font-size: 12px; color: var(--muted); font-weight: 500; }
.st-table th, .st-table td { padding: 10px 14px; }
.st-table th:first-child, .st-table td:first-child { padding-left: 2px; }
.st-table th:last-child, .st-table td:last-child { padding-right: 2px; min-width: 120px; }
.st-table td.st-bal { font-size: 16px; font-weight: 700; }
.st-table tr.zero td { color: var(--muted); }
.st-table tr.zero td.st-bal { font-weight: 500; }
.st-table tfoot td { border-bottom: 0; font-weight: 600; }
.st-table tfoot small { font-weight: 500; color: var(--muted); font-size: 12px; }

/* ---------- one-line item count ---------- */
.ic-compare { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.ic-compare b { color: var(--text); }
.ic-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto auto; gap: 8px; align-items: end; }
.ic-row .field { display: grid; gap: 4px; margin: 0; }
.ic-row label { font-size: 12.5px; color: var(--muted); }
.ic-qty-wrap { position: relative; }
.ic-qty-wrap .input { padding-right: 44px; }
.ic-qty-wrap .ic-unit { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; pointer-events: none; }
.ic-time { margin-top: 6px; }
@media (max-width: 480px) {
  .ic-row { grid-template-columns: 1fr 1fr; }
  .ic-row .btn-primary { grid-column: 1 / 2; }
}
.item-grid > div, .col-data > .card { min-width: 0; }
.st-binsm { display: none; }
@media (max-width: 520px) {
  .st-bincol { display: none; }
  .st-binsm { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
  .st-table th, .st-table td { padding: 10px 8px; white-space: normal; }
  .st-table td.st-name { overflow-wrap: anywhere; }
  .st-table th:last-child, .st-table td:last-child { min-width: 72px; white-space: nowrap; }
}
.st-table td.st-name small.st-binsm { display: none; }
@media (max-width: 520px) { .st-table td.st-name small.st-binsm { display: block; } }

/* ---------- "where is it" line in product info ---------- */
.pi-where { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; margin-top: 12px; padding: 10px 12px; border-radius: 11px; background: var(--primary-soft); }
.pi-where.none { background: var(--surface-2); }
.pi-where-icon { font-size: 20px; line-height: 1.2; }
.pi-where-bin { font-size: 18px; font-weight: 700; overflow-wrap: anywhere; }
.pi-where.none .pi-where-bin { font-size: 14px; font-weight: 500; color: var(--muted); }
.pi-src-tag { font-size: 11.5px; font-weight: 500; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 99px; padding: 1px 8px; vertical-align: middle; white-space: nowrap; }
.pi-where-more { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- combo box (pick from list or type) ---------- */
.combo { position: relative; }
.combo .input { padding-right: 40px; }
.combo-toggle { position: absolute; right: 2px; top: 2px; bottom: 2px; width: 38px; border: 0; background: transparent; color: var(--muted); font-size: 16px; cursor: pointer; border-radius: 9px; }
.combo-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); min-width: 220px;
  max-height: 260px; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 4px;
}
.combo-list [role="option"] { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 10px 10px; border-radius: 8px; cursor: pointer; font-size: 14.5px; }
.combo-list [role="option"]:hover, .combo-list [role="option"].on { background: var(--primary-soft); }
.combo-list [role="option"] small { color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.combo-group { font-size: 11.5px; color: var(--muted); padding: 8px 10px 4px; font-weight: 600; position: sticky; top: -4px; background: var(--surface); }
.combo-new { color: var(--primary); font-weight: 600; }
.combo-empty, .combo-wait { padding: 10px; font-size: 13px; color: var(--muted); }
.combo-list { min-width: min(300px, calc(100vw - 32px)); }
.combo-list [role="option"] b, .combo-list [role="option"] { white-space: nowrap; }
.combo-list [role="option"] small { min-width: 0; }

/* ---------- Stock tab v2: status filter + 5 value cards ---------- */
.stock-scope { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, .9fr) auto; }
.sum-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.sum-no { display: inline-grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; background: var(--surface-2); color: var(--muted); font-size: 10.5px; font-weight: 700; margin-right: 6px; vertical-align: 1px; }
.sum-tile.sum-stock { background: var(--primary-soft); border-color: transparent; }
.sum-tile.is-neg { border-color: var(--danger); background: var(--danger-soft); }
.sum-tile.is-neg .sum-value { color: var(--danger); }
.sum-tile.is-pos .sum-value { color: var(--ok); }
@media (max-width: 1100px) { .sum-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .sum-grid .sum-tile:last-child { grid-column: 1 / -1; } }
@media (max-width: 640px) {
  .stock-scope { grid-template-columns: 1fr 1fr; }
  .stock-scope #scopeClear { grid-column: auto; }
  .sum-tile:not(.sum-progress) .sum-sub { display: block; }
}
.sec-label { font-size: 12.5px; font-weight: 600; color: var(--muted); margin: 2px 2px 6px; }
.stock-scope { margin-bottom: 14px; }

/* =====================================================================
   DESIGN v2 — clean white, black pill buttons, grey filled inputs,
   rounded-20 cards, floating bottom nav (reference: mobile app mockup)
   ===================================================================== */
:root {
  --bg: #ffffff; --surface: #ffffff; --surface-2: #f2f3f5; --text: #111214; --muted: #8a8f98;
  --border: #ececef; --primary: #111214; --primary-ink: #ffffff; --primary-soft: #f2f3f5;
  --accent: #2f6bff; --accent-soft: #e9f0ff;
  --shadow: 0 2px 10px rgba(17, 18, 20, .05);
  --radius: 20px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0f11; --surface: #17181b; --surface-2: #222328; --text: #f4f5f6; --muted: #9a9ea6;
    --border: #26272c; --primary: #f4f5f6; --primary-ink: #111214; --primary-soft: #222328;
    --accent: #6b95ff; --accent-soft: #1b2440; --shadow: 0 2px 10px rgba(0, 0, 0, .35);
  }
}
:root[data-theme="dark"] {
  --bg: #0e0f11; --surface: #17181b; --surface-2: #222328; --text: #f4f5f6; --muted: #9a9ea6;
  --border: #26272c; --primary: #f4f5f6; --primary-ink: #111214; --primary-soft: #222328;
  --accent: #6b95ff; --accent-soft: #1b2440; --shadow: 0 2px 10px rgba(0, 0, 0, .35);
}

/* chrome */
.topbar { border-bottom: 0; background: var(--bg); }
.brand-mark { border-radius: 50%; width: 32px; height: 32px; }
.badge-beta { background: var(--primary); color: var(--primary-ink); }
.topbar-right .btn-ghost { border-radius: 999px; }
#themeBtn { background: var(--surface-2); width: 40px; padding: 0; }
@media (min-width: 760px) { #themeBtn { width: auto; padding: 0 14px; } }

/* buttons & inputs */
.btn { border-radius: 999px; font-weight: 600; }
.btn:not(.btn-primary):not(.btn-ghost):not(.btn-danger) { background: var(--surface); border-color: var(--border); }
.input, .textarea { border-radius: 14px; background: var(--surface-2); border-color: transparent; }
.input:focus, .textarea:focus { outline: 2px solid var(--primary); }
.search-box .input { border-radius: 999px; min-height: 50px; padding-left: 46px; }
.search-box svg { left: 16px; }
.photo-search-btn { min-height: 50px; }
.chip { border: 0; background: var(--surface-2); color: var(--muted); font-weight: 600; min-height: 36px; padding: 0 16px; }
.chip[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); }

/* page heading: big & bold */
.page-head { margin: 4px 2px 16px; }
.page-head h1 { font-size: 30px; line-height: 1.15; font-weight: 700; letter-spacing: -.01em; }
.page-head p { font-size: 14px; margin-top: 6px; }
.search-row { padding-bottom: 12px; }
.list-meta { font-weight: 600; color: var(--text); font-size: 15px; margin: 6px 2px 12px; }

/* item list: square photo left + item name */
.item-list { gap: 12px; }
.item-card {
  grid-template-columns: 84px 1fr; gap: 14px; padding: 10px; border: 0;
  border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); outline: 1px solid var(--border);
}
.item-card:hover { outline-color: var(--primary); }
.thumb { width: 84px; height: 84px; border-radius: 16px; }
.item-title-row { font-weight: 700; font-size: 16px; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
.item-stats { margin-top: 6px; }
.pill { padding: 2px 10px; }
.pill-cat { background: var(--accent-soft); color: var(--accent); }
.item-th { color: var(--text); }

/* cards & tiles */
.card, .sum-tile, .pi-box, .pi-where, .st-tile, .panel { border-radius: 20px; }
.card { border: 0; outline: 1px solid var(--border); }
.sum-tile { border: 0; background: var(--surface-2); box-shadow: none; padding: 14px; }
.sum-tile.sum-stock { background: var(--primary); color: var(--primary-ink); }
.sum-tile.sum-stock .sum-label, .sum-tile.sum-stock .sum-sub { color: inherit; opacity: .7; }
.sum-tile.sum-stock .sum-no { background: rgba(255,255,255,.18); color: inherit; }
.sum-tile.is-neg { border: 0; }
.sum-value { font-size: 22px; }
.pi-box.pi-main { background: var(--primary); color: var(--primary-ink); }
.pi-box.pi-main .pi-label, .pi-box.pi-main .pi-src, .pi-box.pi-main small { color: inherit; opacity: .7; }
.pi-box.pi-main.is-diff { background: var(--warn-soft); color: var(--text); }
.pi-where { background: var(--accent-soft); }
.photo-main { border-radius: 18px; }

/* side nav (desktop) */
.sidenav { background: var(--bg); }
.sidenav a { border-radius: 999px; }
.sidenav a[aria-current="page"] { color: var(--primary-ink); background: var(--primary); }

/* floating bottom nav (phone) */
@media (max-width: 759px) {
  .sidenav {
    left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); border: 0;
    border-radius: 28px; background: var(--surface); box-shadow: 0 8px 28px rgba(17, 18, 20, .14);
    padding: 8px; outline: 1px solid var(--border);
  }
  .sidenav a { border-radius: 20px; padding: 8px 4px; }
  .sidenav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
  .app { padding-bottom: 120px; }
  body.has-nav .toast { bottom: calc(96px + env(safe-area-inset-bottom)); }
  .page-head h1 { font-size: 27px; }
}

/* login: hero + welcome */
.login-wrap { min-height: 92vh; }
.login-card { padding: 0 0 22px; overflow: hidden; border: 0; border-radius: 32px; box-shadow: 0 20px 50px rgba(17, 18, 20, .12); gap: 14px; }
.login-card > *:not(.login-hero) { margin: 0 22px; }
.login-hero {
  display: grid; place-items: center; gap: 6px; padding: 46px 20px 54px; text-align: center; color: #fff;
  background: radial-gradient(120% 90% at 30% 10%, #3a3f47 0%, #15171a 60%, #0b0c0e 100%);
  border-radius: 0 0 50% 50% / 0 0 34px 34px;
}
.login-logo { width: 64px; height: 64px; border-radius: 50%; background: #fff; color: #111; display: grid; place-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.login-brand { font-size: 26px; font-weight: 800; letter-spacing: .04em; margin-top: 6px; }
.login-tag { font-size: 13px; opacity: .8; }
.login-body { text-align: center; }
.login-card .login-body h1 { font-size: 26px; font-weight: 800; letter-spacing: .02em; }
.login-card .login-body p { margin-top: 4px; }
.login-more summary { list-style: none; cursor: pointer; }
.login-more summary::-webkit-details-marker { display: none; }
.login-more[open] summary { margin-bottom: 12px; }
.login-fields { display: grid; gap: 12px; }
.sum-value { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: clamp(15px, 4.1vw, 22px); }
@media (min-width: 760px) { .sum-value { font-size: clamp(17px, 1.5vw, 22px); } }

/* =====================================================================
   BRAND COLORS — navy #082D73 (primary) + yellow #F3BF14 (accent)
   ===================================================================== */
:root {
  --primary: #082D73; --primary-ink: #ffffff; --primary-soft: #e8edf7;
  --accent: #F3BF14; --accent-ink: #082D73; --accent-soft: #fdf3d0;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #F3BF14; --primary-ink: #082D73; --primary-soft: #1d2740;
    --accent: #F3BF14; --accent-ink: #082D73; --accent-soft: #3a3010;
  }
}
:root[data-theme="dark"] {
  --primary: #F3BF14; --primary-ink: #082D73; --primary-soft: #1d2740;
  --accent: #F3BF14; --accent-ink: #082D73; --accent-soft: #3a3010;
}
.brand-mark { background: #082D73; color: #F3BF14; }
.badge-beta { background: var(--accent); color: var(--accent-ink); }
.pill-cat { background: var(--accent-soft); color: #7a5c00; }
:root[data-theme="dark"] .pill-cat { color: var(--accent); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pill-cat { color: var(--accent); } }
.item-th, .item-title-row { color: var(--text); }
.item-card:hover { outline-color: var(--accent); }

/* stock-side cards in navy, yellow numbers */
.sum-tile.sum-stock, .pi-box.pi-main { background: #082D73; color: #fff; }
.sum-tile.sum-stock .sum-value, .pi-box.pi-main .pi-value { color: #F3BF14; }
.pi-where { background: var(--accent-soft); }

/* nav: yellow highlight */
.sidenav a[aria-current="page"] { background: #082D73; color: #F3BF14; }
@media (max-width: 759px) {
  .sidenav a[aria-current="page"] { background: #082D73; color: #F3BF14; }
}

/* login hero in navy with yellow logo */
.login-hero { background: radial-gradient(120% 90% at 30% 10%, #1a4aa6 0%, #082D73 55%, #051c4a 100%); }
.login-logo { background: #F3BF14; color: #082D73; }
.login-brand { color: #fff; }
.login-tag { color: #F3BF14; opacity: 1; }

/* =====================================================================
   DESIGN v3 — navy header block, promo banner, section heads,
   category tiles, pill bottom nav (reference 2: "after" mockup)
   ===================================================================== */
/* navy top bar that flows into the page header */
.topbar { background: #082D73; color: #fff; }
.topbar .brand, .topbar .btn-ghost, .topbar .user-name { color: #fff; }
.topbar .user-name { opacity: .7; }
.topbar .brand-mark { background: #F3BF14; color: #082D73; }
.topbar #themeBtn { background: rgba(255,255,255,.12); color: #fff; }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.12); }
.topbar .upload-badge { background: #F3BF14; color: #082D73; border-color: #F3BF14; }

.hero {
  background: #082D73; color: #fff; display: grid; gap: 14px;
  margin: -16px calc(-1 * var(--gutter)) 18px; padding: 8px var(--gutter) 22px;
  border-radius: 0 0 28px 28px;
}
.app.wide .hero { display: none; }
.hero .page-head { margin: 0; }
.hero .page-head h1 { color: #fff; }
.hero .page-head p { color: #F3BF14; opacity: .95; }
.hero .search-box .input { background: #fff; color: #111214; }
.hero .search-box svg { color: #082D73; }
.hero .photo-search-btn { background: #F3BF14; border-color: #F3BF14; color: #082D73; }
@media (min-width: 760px) {
  .hero { margin: 0 0 18px; border-radius: 28px; padding: 22px 24px 24px; }
}

/* promo banner inside the header */
.hero-banner {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; cursor: pointer;
  background: linear-gradient(135deg, rgba(255,255,255,.12), rgba(255,255,255,.04));
  border: 1px solid rgba(255,255,255,.16); border-radius: 22px; padding: 16px 16px 16px 18px;
}
.hero-banner[hidden] { display: none; }
.hb-text { display: grid; gap: 6px; justify-items: start; }
.hb-text b { font-size: 19px; line-height: 1.25; font-weight: 800; letter-spacing: .01em; }
.hb-text span { font-size: 12.5px; opacity: .8; }
.hb-text .hb-btn { opacity: 1; background: #fff; color: #082D73; font-weight: 700; font-size: 13px; padding: 7px 16px; border-radius: 999px; margin-top: 4px; }
.hb-art { width: 112px; height: 94px; }
@media (max-width: 380px) { .hb-art { width: 84px; } .hb-text b { font-size: 17px; } }

/* section heads with "ดูทั้งหมด ›" */
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 18px 2px 10px; }
.sec-head h2 { margin: 0; font-size: 18px; font-weight: 700; }
.link-btn { background: none; border: 0; color: var(--muted); font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; padding: 4px 0; }
.link-btn:hover { color: var(--text); }
.sec-label { display: none; }
#stockSummary + .sec-head { margin-top: 22px; }
.search-row { position: static; background: none; padding-top: 0; }
.search-row-chips { padding-bottom: 6px; }

/* category tiles: icon box + name + chevron, 2 columns */
.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (min-width: 760px) { .cat-grid { grid-template-columns: repeat(3, 1fr); } }
.cat-tile {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; text-align: left;
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 8px 12px 8px 8px; cursor: pointer; min-height: 60px;
}
.cat-tile:hover { border-color: #082D73; }
.cat-ico { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-2); color: #082D73; }
:root[data-theme="dark"] .cat-ico { color: #F3BF14; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .cat-ico { color: #F3BF14; } }
.cat-name { font-weight: 600; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-go { color: var(--muted); font-size: 18px; }
#catBox[hidden] { display: none; }

/* bottom nav: white bar, active tab = navy pill with icon + label */
@media (max-width: 759px) {
  .sidenav { display: flex; justify-content: space-around; gap: 6px; padding: 8px 10px; }
  .sidenav a { flex-direction: row; gap: 8px; padding: 10px 16px; font-size: 13.5px; color: var(--muted); border-radius: 999px; flex: 0 1 auto; }
  .sidenav a[aria-current="page"] { background: #082D73; color: #fff; flex: 1 1 auto; justify-content: center; }
  .sidenav a[aria-current="page"] svg { color: #F3BF14; }
}
.login-card > .btn-block, .login-card > .login-more { width: auto; }
.login-more summary.btn-block { width: 100%; }

/* =====================================================================
   MINIMAL PASS — mostly white, navy only for text & key actions,
   yellow as a small accent. Overrides the heavier navy blocks above.
   ===================================================================== */
:root { --navy: #082D73; --navy-soft: #eef2f9; --yellow: #F3BF14; --yellow-soft: #fff8e1; }
:root[data-theme="dark"] { --navy-soft: #1a2133; --yellow-soft: #2e2810; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --navy-soft: #1a2133; --yellow-soft: #2e2810; } }

/* top bar: white */
.topbar { background: var(--bg); color: var(--text); border-bottom: 1px solid var(--border); }
.topbar .brand, .topbar .btn-ghost { color: var(--text); }
.topbar .user-name { color: var(--muted); opacity: 1; }
.topbar .brand-mark { background: var(--navy); color: var(--yellow); }
.topbar #themeBtn { background: var(--surface-2); color: var(--text); }
.topbar .btn-ghost:hover { background: var(--surface-2); }

/* page header: white, navy title, no colour block */
.hero { background: transparent; color: var(--text); padding-top: 14px; padding-bottom: 6px; margin-bottom: 4px; border-radius: 0; }
@media (min-width: 760px) { .hero { padding: 6px 0 6px; border-radius: 0; } }
.hero .page-head h1 { color: var(--navy); }
:root[data-theme="dark"] .hero .page-head h1 { color: var(--text); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .hero .page-head h1 { color: var(--text); } }
.hero .page-head p { color: var(--muted); opacity: 1; }
.hero .search-box .input { background: var(--surface-2); color: var(--text); }
.hero .search-box svg { color: var(--muted); }
.hero .photo-search-btn, .photo-search-btn { background: var(--navy); border-color: var(--navy); color: #fff; }

/* banner: soft yellow card, navy text */
.hero-banner { background: var(--yellow-soft); border: 0; color: var(--navy); }
:root[data-theme="dark"] .hero-banner { color: var(--text); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .hero-banner { color: var(--text); } }
.hb-text span { opacity: .75; }
.hb-text .hb-btn { background: var(--navy); color: #fff; }
.hb-art path[fill="#F3BF14"] { opacity: .35; }
.hb-art path[stroke="#F3BF14"] { stroke: var(--navy); }
.hb-art rect[fill="#fff"] { fill: var(--yellow); }

/* stock cards & item quantity box: white with thin border, navy number */
.sum-tile { background: var(--surface); outline: 1px solid var(--border); }
.sum-tile.sum-stock { background: var(--surface); color: var(--text); outline: 1px solid var(--border); box-shadow: inset 4px 0 0 var(--yellow); }
.sum-tile.sum-stock .sum-label, .sum-tile.sum-stock .sum-sub { color: var(--muted); opacity: 1; }
.sum-tile.sum-stock .sum-value { color: var(--navy); }
.sum-tile.sum-stock .sum-no { background: var(--yellow-soft); color: var(--navy); }
.sum-tile.is-neg { background: var(--surface); outline: 1px solid var(--border); box-shadow: inset 4px 0 0 var(--danger); }
.pi-box { background: var(--surface); outline: 1px solid var(--border); }
.pi-box.pi-main { background: var(--surface); color: var(--text); box-shadow: inset 4px 0 0 var(--yellow); }
.pi-box.pi-main .pi-value { color: var(--navy); }
.pi-box.pi-main .pi-label, .pi-box.pi-main .pi-src, .pi-box.pi-main small { color: var(--muted); opacity: 1; }
.pi-box.pi-main.is-diff { background: var(--surface); box-shadow: inset 4px 0 0 var(--warn); }
.pi-where { background: var(--surface-2); }
:root[data-theme="dark"] .sum-tile.sum-stock .sum-value, :root[data-theme="dark"] .pi-box.pi-main .pi-value { color: var(--yellow); }

/* chips, categories, pills: quieter */
.chip[aria-pressed="true"] { background: var(--navy-soft); color: var(--navy); }
:root[data-theme="dark"] .chip[aria-pressed="true"] { color: var(--text); }
.cat-tile { border-color: var(--border); }
.cat-ico { background: var(--navy-soft); color: var(--navy); }
.pill-cat { background: var(--surface-2); color: var(--muted); }
.item-card:hover { outline-color: var(--navy); }

/* navs: light highlight instead of solid navy */
.sidenav a[aria-current="page"] { background: var(--navy-soft); color: var(--navy); }
.sidenav a[aria-current="page"] svg { color: var(--navy); }
@media (max-width: 759px) {
  .sidenav a[aria-current="page"] { background: var(--navy-soft); color: var(--navy); }
  .sidenav a[aria-current="page"] svg { color: var(--navy); }
}
:root[data-theme="dark"] .sidenav a[aria-current="page"], :root[data-theme="dark"] .sidenav a[aria-current="page"] svg { color: var(--yellow); }

/* login: white card, small navy mark, no dark block */
.login-hero { background: var(--surface); color: var(--text); padding: 40px 20px 8px; border-radius: 0; }
.login-logo { background: var(--navy); color: var(--yellow); box-shadow: none; }
.login-brand { color: var(--navy); }
.login-tag { color: var(--muted); }
.login-card { box-shadow: 0 10px 40px rgba(17, 18, 20, .08); outline: 1px solid var(--border); }
.badge-beta { background: var(--yellow-soft); color: #8a6a00; }

/* =====================================================================
   CONTRAST PASS — page background is a soft grey, every object
   (cards, tiles, inputs on the page, nav) is white and stands out
   ===================================================================== */
:root { --bg: #f3f5f8; --surface: #ffffff; --surface-2: #eef1f5; --border: #e3e7ee;
        --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 14px rgba(16, 24, 40, .06); }
:root[data-theme="dark"] { --bg: #0b0c0e; --surface: #1a1b1f; --surface-2: #24262b; --border: #2c2e34; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg: #0b0c0e; --surface: #1a1b1f; --surface-2: #24262b; --border: #2c2e34; } }

body { background: var(--bg); }
.topbar { background: var(--bg); border-bottom: 0; }
.topbar #themeBtn { background: var(--surface); box-shadow: var(--shadow); }
.sidenav { background: var(--bg); border-right: 0; }
@media (max-width: 759px) { .sidenav { background: var(--surface); } }

/* inputs sitting directly on the page → white with shadow */
.hero .search-box .input, .stock-scope .input { background: var(--surface); box-shadow: var(--shadow); }
/* inputs inside cards stay light grey */
.card .input, .card .textarea { background: var(--surface-2); box-shadow: none; }

/* objects: white + soft shadow, no hairline needed */
.item-card, .card, .cat-tile, .sum-tile, .sum-tile.sum-stock, .sum-tile.is-neg, .login-card {
  background: var(--surface); box-shadow: var(--shadow); outline: 0; border: 0;
}
.sum-tile.sum-stock { box-shadow: inset 4px 0 0 var(--yellow), var(--shadow); }
.sum-tile.is-neg { box-shadow: inset 4px 0 0 var(--danger), var(--shadow); }
.item-card:hover, .cat-tile:hover { box-shadow: 0 0 0 1.5px var(--navy), var(--shadow); }
.chip { background: var(--surface); box-shadow: var(--shadow); }
.chip[aria-pressed="true"] { background: var(--navy); color: #fff; }
.hero-banner { box-shadow: var(--shadow); }
.thumb { background: var(--surface-2); }

/* =====================================================================
   LOGIN — keep the bold brand look (navy hero, yellow logo)
   ===================================================================== */
.login-card { outline: 0; box-shadow: 0 20px 50px rgba(8, 45, 115, .18); }
.login-hero {
  background: radial-gradient(120% 90% at 30% 10%, #1a4aa6 0%, #082D73 55%, #051c4a 100%);
  color: #fff; padding: 46px 20px 54px;
  border-radius: 0 0 50% 50% / 0 0 34px 34px;
}
.login-logo { background: #F3BF14; color: #082D73; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); }
.login-brand { color: #fff; }
.login-tag { color: #F3BF14; }
.login-card .login-body h1 { color: #082D73; }
:root[data-theme="dark"] .login-card .login-body h1 { color: #F3BF14; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .login-card .login-body h1 { color: #F3BF14; } }
.login-card #anonBtn { background: #082D73; border-color: #082D73; color: #fff; }
.login-card #loginBtn { background: #F3BF14; border-color: #F3BF14; color: #082D73; }
.login-more summary { border: 2px solid #082D73; color: #082D73; background: transparent; }
:root[data-theme="dark"] .login-more summary { border-color: #F3BF14; color: #F3BF14; }
.login-wrap { background: radial-gradient(80% 60% at 50% 0%, #fff8e1 0%, transparent 70%); }
.login-card .login-more summary.btn { border: 2px solid #082D73; color: #082D73; background: #fff; }
:root[data-theme="dark"] .login-card .login-more summary.btn { border-color: #F3BF14; color: #F3BF14; background: transparent; }
