/* หน้าผู้ดูแล TCGCare — สมุดบัญชีเคลม: แถวมีแถบสถานะซ้าย (เว็บ/ชีต/ยกเลิก) + ป้ายรหัสชุดสินค้า */
:root {
  color-scheme: light;
  --navy: #142d42; --navy-2: #1d3b55; --paper: #f3f6f5; --surface: #fff; --ink: #172b3a; --muted: #5f707c; --line: #dce4e2; --line-2: #eef2f1;
  --teal: #127a70; --teal-ink: #0d6159; --teal-soft: #e5f2ee;
  --sheet: #2f5e8a; --sheet-soft: #e8eff7;
  --amber: #9a6510; --amber-soft: #fbf0d9;
  --brick: #b0433a; --brick-soft: #fbebe9;
  --radius: 12px;
  --font: "Leelawadee UI", "Noto Sans Thai", "Sarabun", Tahoma, system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  font-family: var(--font); font-size: 15px; line-height: 1.6; color: var(--ink); background: var(--paper);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--paper); }
h1, h2, h3, p, dl, dd, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }
a { color: var(--teal); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: progress; opacity: .55; }
[hidden] { display: none !important; }
code { font-family: var(--mono); font-size: .86em; overflow-wrap: anywhere; }
:focus-visible { outline: 3px solid #74c6b9; outline-offset: 2px; border-radius: 6px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- ปุ่มและฟอร์ม ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 14px; text-decoration: none; transition: background .15s, border-color .15s; }
.btn:hover { border-color: #b8c7c4; }
.btn-primary { background: var(--teal); border-color: var(--teal); color: #fff; -webkit-text-fill-color: #fff; }
.btn-primary:hover { background: var(--teal-ink); }
.btn-danger { background: var(--brick); border-color: var(--brick); color: #fff; -webkit-text-fill-color: #fff; }
.btn-danger-ghost { color: var(--brick); border-color: #ecc9c4; }
.btn-danger-ghost:hover { background: var(--brick-soft); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--line-2); }
.btn-sm { min-height: 34px; padding: 4px 12px; font-size: 13px; }
.btn-icon { min-width: 42px; padding: 0; font-size: 20px; }
.btn-block { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--teal); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
input, select, textarea { width: 100%; min-height: 44px; border: 1px solid #cfdad8; border-radius: 10px; background: #fff; padding: 9px 12px; font-size: 16px; }
textarea { resize: vertical; min-height: 72px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px #127a7022; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; }
.field-inline { display: grid; gap: 2px; }
.field-inline > span { font-size: 11px; font-weight: 600; color: var(--muted); }
.field-inline select { min-height: 38px; padding: 6px 10px; font-size: 14px; }
.form-error { color: var(--brick); background: var(--brick-soft); border-radius: 8px; padding: 8px 12px; font-size: 13px; }
.stack-form { display: grid; gap: 12px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line-2); }
.stack-form h3 { font-size: 15px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }

/* ---------- เข้าสู่ระบบ ---------- */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: repeating-linear-gradient(180deg, transparent 0 31px, #e3eae8 31px 32px), var(--paper); }
.login-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: grid; gap: 10px; box-shadow: 0 18px 40px #142d4214; }
.login-card h1 { font-size: 24px; margin: 8px 0 4px; }
.login-card label { font-size: 13px; font-weight: 600; margin-top: 4px; }
.login-card .btn { margin-top: 8px; min-height: 48px; }
.login-brand, .side-brand { display: flex; align-items: center; gap: 10px; }
.login-brand strong { display: block; font-size: 17px; }
.login-brand span { font-size: 12px; color: var(--muted); }
.mark { width: 38px; height: 38px; border-radius: 11px; background: var(--navy); color: #fff; display: grid; place-items: center; font-size: 20px; flex-shrink: 0; }
.login-help { font-size: 12px; color: var(--muted); text-align: center; }
.login-back { font-size: 13px; text-align: center; }

/* ---------- โครงแอป ---------- */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--navy); color: #d6e2e8; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.side-brand { color: #fff; text-decoration: none; font-weight: 700; padding: 4px 8px 20px; }
.side-brand .mark { background: #ffffff1a; }
.side-brand small { display: block; font-weight: 400; font-size: 11px; color: #9fb5c1; }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: #c7d6de; text-decoration: none; font-weight: 600; }
.nav a:hover { background: #ffffff10; color: #fff; }
.nav a[aria-current] { background: #ffffff1c; color: #fff; box-shadow: inset 3px 0 #6fd0c0; }
.nav-icon { width: 20px; text-align: center; opacity: .85; }
.nav-badge { margin-left: auto; background: #e0a43a; color: #2b1d02; border-radius: 999px; font-size: 11px; padding: 0 7px; line-height: 18px; }
.side-foot { margin-top: auto; padding: 12px; font-size: 12px; }
.side-foot a { color: #9fb5c1; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 24px;
  background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 20px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.sync-state { font-size: 12px; color: var(--muted); }
.user-chip { display: grid; text-align: right; line-height: 1.25; padding: 0 6px; }
.user-chip span { font-size: 13px; font-weight: 700; }
.user-chip small { font-size: 11px; color: var(--muted); }
.banner { margin: 12px 24px 0; padding: 10px 14px; border-radius: 10px; background: var(--amber-soft); color: #5c3d07; font-size: 13px; }
.view { padding: 20px 24px 40px; display: grid; gap: 16px; align-content: start; outline: none; }
.lede { color: var(--muted); font-size: 14px; }

/* ---------- การ์ด / ตาราง ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { font-size: 16px; display: flex; align-items: center; gap: 8px; }
.count { font-size: 12px; background: var(--line-2); border-radius: 999px; padding: 0 8px; line-height: 20px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { font-size: 11px; font-weight: 600; color: var(--muted); text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.data-table td { padding: 9px 8px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover td { background: #f6faf9; }
.up { color: var(--brick); font-weight: 700; } .down { color: var(--sheet); font-weight: 700; }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; }

/* ป้ายรหัสชุดสินค้า */
.set-chip { display: inline-flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 11.5px; font-weight: 700; letter-spacing: .02em;
  border: 1px solid #c9d6d3; background: #fbfcfc; border-radius: 6px; padding: 1px 6px; margin: 1px 4px 1px 0; white-space: nowrap; color: var(--ink); }
.set-chip i { font-style: normal; font-family: var(--font); font-size: 10.5px; font-weight: 700; color: var(--amber); }
.set-chip.is-deposit { border-color: #e6c88f; background: var(--amber-soft); }
.badge { font-style: normal; display: inline-block; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.badge-web { background: var(--teal-soft); color: var(--teal-ink); }
.badge-sheet { background: var(--sheet-soft); color: var(--sheet); }
.badge-void { background: var(--brick-soft); color: var(--brick); }
.badge-held { background: var(--amber-soft); color: var(--amber); }

/* ---------- ภาพรวม ---------- */
.kpis { display: grid; grid-template-columns: 1.6fr repeat(3, 1fr); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 2px; }
.kpi span { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi strong { font-size: 26px; font-variant-numeric: tabular-nums; line-height: 1.25; overflow-wrap: anywhere; }
.kpi small { font-size: 12px; color: var(--muted); }
.kpi-lead { background: var(--navy); border-color: var(--navy); color: #fff; }
.kpi-lead span, .kpi-lead small { color: #a9c0cb; }
.kpi-lead strong { font-size: 32px; }
.overview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card-wide { grid-column: 1 / -1; }
.tasks { display: grid; gap: 8px; }
.task { width: 100%; display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 12px; text-align: left; background: #fafcfb; border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 12px; }
.task b { font-size: 22px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.task.has-work { background: var(--amber-soft); border-color: #efd9a8; }
.task.has-work b { color: var(--amber); }
.task strong { display: block; font-size: 14px; }
.task small { color: var(--muted); font-size: 12px; }
.task i { font-style: normal; color: var(--muted); font-size: 20px; }
.task:hover { border-color: #b8c7c4; }
.activity-list { display: grid; }
.act { display: grid; grid-template-columns: 116px 1fr; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line-2); font-size: 14px; }
.act:last-child { border-bottom: 0; }
.act time { color: var(--muted); font-size: 12px; padding-top: 2px; }
.act small { display: block; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.act-void strong::after, .act-correct strong::after { content: ""; }

/* ---------- รายการ (สมุดบัญชี) ---------- */
.toolbar { display: grid; gap: 10px; }
.search { position: relative; }
.search span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 18px; pointer-events: none; }
.search input { padding-left: 38px; padding-right: 40px; min-height: 46px; }
.search kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-family: var(--mono); font-size: 11px; border: 1px solid var(--line); border-radius: 5px; padding: 0 6px; color: var(--muted); background: #fff; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filters .field-inline { flex: 1 1 130px; }
.result-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; }
.result-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.ledger { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.ledger-head, .ledger-row { display: grid; grid-template-columns: 112px minmax(0, 1.5fr) minmax(0, 1.5fr) 72px 128px 64px; gap: 12px; align-items: center; padding: 10px 16px 10px 18px; }
.ledger-head { font-size: 11px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); background: #fafcfb; }
.ledger-row { width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line-2); box-shadow: inset 4px 0 var(--teal); font-size: 14px; }
.ledger-row:last-child { border-bottom: 0; }
.ledger-row:hover { background: #f6faf9; }
.ledger-row.tone-sheet { box-shadow: inset 4px 0 var(--sheet); }
.ledger-row.tone-void { box-shadow: inset 4px 0 var(--brick); color: var(--muted); }
.ledger-row.tone-void .cell-total { text-decoration: line-through; }
.ledger-row.tone-held { box-shadow: inset 4px 0 var(--amber); background: #fffcf4; }
.ledger-row.tone-held .cell-total { color: var(--amber); }
.cell-date { font-size: 12px; color: var(--muted); }
.cell-name { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; min-width: 0; }
.cell-name strong { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-total { font-weight: 700; }

/* ---------- แผงรายละเอียด ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: #0f1f2c55; z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100%); background: var(--surface); z-index: 21; display: flex; flex-direction: column;
  box-shadow: -18px 0 40px #142d4226; transform: translateX(24px); opacity: 0; transition: transform .18s ease, opacity .18s ease; }
.drawer.is-open { transform: none; opacity: 1; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 18px; overflow-wrap: anywhere; }
.drawer-body { overflow: auto; padding: 18px; display: grid; gap: 16px; align-content: start; }
body.drawer-open { overflow: hidden; }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: 10px; background: var(--teal-soft); }
.detail-head.tone-sheet { background: var(--sheet-soft); }
.detail-head.tone-void { background: var(--brick-soft); }
.detail-head.tone-held { background: var(--amber-soft); }
.held-note { display: grid; gap: 2px; padding: 10px 12px; border: 1px solid #efd9a8; background: #fffcf4; border-radius: 10px; font-size: 13px; }
.held-note strong { color: var(--amber); }
.eyebrow { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
.detail-total { font-size: 26px; font-variant-numeric: tabular-nums; }
.detail-total small { font-size: 13px; font-weight: 400; }
.facts { display: grid; gap: 6px; font-size: 14px; }
.facts div { display: grid; grid-template-columns: 96px 1fr; gap: 8px; }
.facts dt { color: var(--muted); }
.items-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.items-table th { font-size: 11px; color: var(--muted); font-weight: 600; text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.items-table td { padding: 8px 6px; border-bottom: 1px solid var(--line-2); }
.history h3 { font-size: 14px; margin-bottom: 6px; }
.history li { font-size: 13px; padding: 8px 10px; border-left: 3px solid var(--line); margin-bottom: 6px; background: #fafcfb; border-radius: 0 8px 8px 0; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.edit-form { display: grid; gap: 14px; }
.edit-items { display: grid; gap: 8px; }
.edit-item { display: grid; grid-template-columns: 1.3fr .7fr 1fr .9fr 42px; gap: 6px; }
.edit-item input, .edit-item select { min-height: 42px; font-size: 15px; padding: 6px 8px; }
.diff { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 12px; background: #fafcfb; border-radius: 10px; font-size: 14px; }
.diff strong { font-variant-numeric: tabular-nums; }

/* ---------- ตรวจสอบ ---------- */
.review-section .empty { padding: 16px; }
.dup-group { border: 1px solid #efd9a8; background: #fffcf4; border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; display: grid; gap: 8px; }
.dup-reason { font-size: 12px; font-weight: 700; color: var(--amber); }
.dup-group li, .plain-list li { display: flex; align-items: center; gap: 8px; }
.plain-list { display: grid; gap: 8px; }
.dup-entry { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.2fr) auto; gap: 4px 10px; align-items: center; text-align: left;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 14px; }
.dup-entry small { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }
.dup-entry:hover { border-color: #b8c7c4; }
.held-section { border-color: #efd9a8; }
.held-section .card-head h2 { display: flex; align-items: center; gap: 8px; }
.held-section .count { font-size: 12px; background: var(--amber); color: #fff; border-radius: 999px; padding: 0 8px; }
.held-group .dup-reason { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.held-group ul { display: grid; gap: 8px; }
.row-buttons { display: flex; gap: 6px; flex-shrink: 0; }
.alert-bar { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center; padding: 12px 16px; margin-bottom: 12px; border-radius: var(--radius);
  background: var(--amber-soft); border: 1px solid #efd9a8; color: var(--ink); text-decoration: none; }
.alert-bar strong { color: var(--amber); }
.alert-bar span { grid-column: 1; font-size: 13px; color: var(--muted); }
.alert-bar i { grid-row: 1 / 3; grid-column: 2; font-style: normal; font-size: 22px; color: var(--amber); }
.alert-bar:hover { border-color: #e2c27e; }
.alert-strict { background: var(--brick-soft); border-color: #ecc9c4; }
.alert-strict strong, .alert-strict i { color: var(--brick); }

/* ---------- ทีม ---------- */
.team-table select { min-height: 36px; font-size: 14px; padding: 4px 8px; }
.row-actions { white-space: nowrap; text-align: right; }

/* ---------- dialog / toast ---------- */
.confirm-dialog { border: 0; border-radius: 14px; padding: 0; width: min(440px, calc(100% - 32px)); box-shadow: 0 24px 60px #0f1f2c40; color: var(--ink); }
.confirm-dialog::backdrop { background: #0f1f2c66; }
.confirm-dialog form { padding: 20px; display: grid; gap: 12px; }
.confirm-dialog h2 { font-size: 18px; }
.confirm-summary { font-size: 15px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 40; display: grid; gap: 8px; width: min(420px, calc(100% - 32px)); pointer-events: none; }
.toast { background: var(--navy); color: #fff; border-radius: 10px; padding: 11px 14px; font-size: 14px; box-shadow: 0 10px 24px #0f1f2c33; transition: opacity .3s; }
.toast-error { background: var(--brick); }
.toast.is-leaving { opacity: 0; }

/* ---------- สร้างรายงาน ---------- */
@font-face { font-family: "Anuphan"; src: url(/fonts/anuphan-thai.woff2) format("woff2"); font-weight: 500 700; font-display: swap; unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Anuphan"; src: url(/fonts/anuphan-latin.woff2) format("woff2"); font-weight: 500 700; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212; }
@font-face { font-family: "Noto Sans Thai Looped"; src: url(/fonts/looped-thai.woff2) format("woff2"); font-weight: 400 700; font-display: swap; unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Noto Sans Thai Looped"; src: url(/fonts/looped-latin.woff2) format("woff2"); font-weight: 400 700; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212; }
.reports { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 20px; align-items: start; }
.rp-form { display: grid; gap: 20px; padding: 20px; }
.rp-form fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 8px; min-width: 0; }
.rp-form fieldset[disabled] { opacity: .5; }
.rp-form legend { padding: 0; margin-bottom: 8px; font-weight: 700; font-size: 14px; }
.rp-form legend small { font-weight: 400; color: var(--muted); }
.rp-options { display: grid; gap: 8px; }
.rp-two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.rp-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.rp-option, .rp-format { position: relative; display: flex; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--surface); transition: border-color .15s, background .15s; }
.rp-option:hover, .rp-format:hover { border-color: #9fc9c1; }
.rp-option input, .rp-format input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.rp-option span, .rp-format span { display: grid; gap: 1px; }
.rp-option strong, .rp-format strong { font-size: 14px; }
.rp-option small, .rp-format small { font-size: 12px; color: var(--muted); line-height: 1.4; }
.rp-option.is-on, .rp-format.is-on { border-color: var(--teal); background: var(--teal-soft); box-shadow: inset 0 0 0 1px var(--teal); }
.rp-option:focus-within, .rp-format:focus-within { outline: 3px solid #127a7055; outline-offset: 2px; }
.rp-form fieldset[disabled] .rp-option { cursor: not-allowed; }
.rp-formats { display: grid; gap: 8px; }
.rp-file { flex: none; width: 36px; height: 44px; border-radius: 4px 12px 4px 4px; display: grid; place-items: end center; padding-bottom: 6px; font-size: 10px; font-weight: 800; letter-spacing: .04em; color: #fff; }
.rp-file-xlsx { background: #1e7a46; }
.rp-file-csv { background: #4b5b67; }
.rp-file-pdf { background: #b0433a; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--teal); }
.rp-actions { display: grid; gap: 4px; }
.rp-actions .btn { min-height: 48px; font-size: 15px; }
.rp-actions p { margin: 0; }
.rp-preview { position: sticky; top: 84px; display: grid; gap: 8px; min-width: 0; }
.rp-preview-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px; }
.rp-paper { background: #d9e1e4; border-radius: var(--radius); padding: 18px; max-height: calc(100vh - 150px); overflow: auto; }
.rp-paper .rp { background: #fff; box-shadow: 0 8px 24px #0f1f2c24; border-radius: 3px; padding: 46px 45px; min-height: 1123px; margin: 0 auto; }
.rp-paper .rp-wide { min-height: 794px; }

/* เอกสารรายงาน — ใช้ทั้งตัวอย่างบนจอและตอนพิมพ์เป็น PDF */
.rp { font-family: "Noto Sans Thai Looped", var(--font); color: #172b3a; font-size: 11px; line-height: 1.5; }
.rp-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-bottom: 10px; border-bottom: 2px solid #142d42; }
.rp-brand { display: flex; align-items: center; gap: 8px; }
.rp-brand strong { display: block; font-family: "Anuphan", var(--font); font-size: 15px; color: #142d42; line-height: 1.1; }
.rp-brand span { font-size: 10px; color: #5f707c; }
.rp-mark { width: 28px; height: 28px; border-radius: 7px; background: #142d42; color: #fff; display: grid; place-items: center; font-size: 15px; }
.rp-meta { font-size: 10px; color: #5f707c; text-align: right; }
.rp-title { font-family: "Anuphan", var(--font); font-size: 22px; font-weight: 700; color: #142d42; margin: 16px 0 6px; line-height: 1.25; }
.rp-filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.rp-filters span { background: #eef3f5; border-radius: 999px; padding: 1px 10px; font-size: 10px; color: #33495a; }
.rp-kpis { display: grid; grid-template-columns: 1.4fr repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 18px; }
.rp-kpi { border: 1px solid #d5dee5; border-radius: 8px; padding: 8px 12px; display: grid; }
.rp-kpi span { font-size: 9.5px; color: #5f707c; }
.rp-kpi strong { font-family: "Anuphan", var(--font); font-size: 17px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rp-kpi.is-lead { background: #142d42; border-color: #142d42; color: #fff; }
.rp-kpi.is-lead span { color: #c9dce6; }
.rp-kpi.is-lead strong { font-size: 20px; }
.rp-section { margin-bottom: 18px; }
.rp-section h2 { font-family: "Anuphan", var(--font); font-size: 13px; color: #127a70; margin: 0 0 6px; }
.rp-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rp-table th { background: #142d42; color: #fff; font-weight: 600; font-size: 9.5px; padding: 6px 7px; text-align: left; vertical-align: bottom; }
.rp-table td { padding: 5px 7px; border-bottom: 1px solid #e3eaee; vertical-align: middle; }
.rp-table tbody tr.is-alt td { background: #f4f8f9; }
.rp-table tbody.rp-group + tbody.rp-group tr:first-child td { border-top: 1px solid #c9d5dc; }
.rp-table .num { text-align: right; white-space: nowrap; }
.rp-table .ref { font-family: var(--mono); font-size: 8.5px; color: #5f707c; word-break: break-all; }
.rp-table tr.is-muted td { color: #8a97a0; text-decoration: line-through; }
.rp-table tfoot td { font-weight: 700; background: #eef3f5; border-top: 2px solid #142d42; border-bottom: 2px solid #142d42; }
.rp-empty, .rp-empty-note { text-align: center; color: #5f707c; padding: 14px; }
.rp-foot { margin-top: 14px; padding-top: 8px; border-top: 1px solid #d5dee5; font-size: 9.5px; color: #5f707c; }
.print-root { display: none; }

@page { size: A4 portrait; margin: 12mm 12mm 14mm; }
@page wide { size: A4 landscape; margin: 10mm 10mm 12mm; }
@media print {
  html, body.is-printing { background: #fff !important; }
  body.is-printing > :not(#print-root) { display: none !important; }
  body.is-printing .print-root { display: block; }
  .print-root .rp { font-size: 9.5pt; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-root .rp-wide { page: wide; }
  .print-root .rp-section { overflow: visible; }
  .print-root .rp-table thead { display: table-header-group; }
  .print-root .rp-table tfoot { display: table-row-group; }
  .print-root .rp-table tr, .print-root .rp-group { break-inside: avoid; }
  .print-root .rp-section h2 { break-after: avoid; }
  .print-root .rp-kpis, .print-root .rp-head { break-inside: avoid; }
}

/* ---------- มือถือ ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 15; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); box-shadow: 0 -6px 20px #0f1f2c26; }
  .side-brand, .side-foot { display: none; }
  .nav { grid-template-columns: repeat(6, 1fr); gap: 0; }
  .nav a { flex-direction: column; gap: 0; padding: 6px 2px; font-size: 11px; text-align: center; position: relative; min-height: 52px; justify-content: center; }
  .nav a[aria-current] { box-shadow: inset 0 3px #6fd0c0; }
  .nav-icon { font-size: 18px; }
  .nav-badge { position: absolute; top: 4px; right: calc(50% - 22px); margin: 0; }
  .main { padding-bottom: 72px; }
  .topbar { padding: 10px 16px; }
  .topbar h1 { font-size: 18px; }
  .sync-state, .user-chip small { display: none; }
  .user-chip { max-width: 110px; }
  .user-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .banner { margin: 10px 16px 0; }
  .view { padding: 16px 16px 32px; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .kpi-lead { grid-column: 1 / -1; }
  .kpi { padding: 10px 12px; }
  .kpi strong { font-size: 20px; }
  .kpi small { font-size: 11px; }
  .kpi-lead strong { font-size: 28px; }
  .overview-grid { grid-template-columns: minmax(0, 1fr); }
  .filters { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px 4px; scrollbar-width: none; }
  .filters::-webkit-scrollbar { display: none; }
  .filters .field-inline { flex: 0 0 138px; }
  #logout { min-height: 38px; padding: 6px 10px; font-size: 13px; }
  .ledger-head { display: none; }
  .ledger-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name total" "items items" "date source"; gap: 4px 10px; padding: 12px 14px 12px 16px; }
  .cell-name { grid-area: name; } .cell-total { grid-area: total; } .cell-items { grid-area: items; } .cell-date { grid-area: date; } .cell-source { grid-area: source; text-align: right; }
  .cell-num { display: none; }
  .drawer { top: auto; width: 100%; height: 92vh; border-radius: 16px 16px 0 0; transform: translateY(24px); }
  .act { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .edit-item { grid-template-columns: 1fr 1fr 42px; }
  .edit-item select[name=product] { grid-column: 1 / 3; }
  .edit-item [data-remove] { grid-row: 1; grid-column: 3; }
  .dup-entry { grid-template-columns: minmax(0, 1fr) auto; }
  .dup-entry > span:nth-of-type(1) { grid-column: 1 / -1; grid-row: 2; }
  .team-table thead { display: none; }
  .team-table tr { display: grid; grid-template-columns: 1fr auto; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
  .team-table td { border: 0; padding: 0; }
  .team-table .row-actions { grid-column: 1 / -1; text-align: left; }
  .toasts { bottom: 84px; }
  .reports { grid-template-columns: minmax(0, 1fr); }
  .rp-preview { position: static; }
  .rp-paper { padding: 8px; max-height: 70vh; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ---------- หลายร้าน ---------- */
.accent-1d5fa8 { --accent: #1d5fa8; } .accent-b5541c { --accent: #b5541c; } .accent-6b3fa0 { --accent: #6b3fa0; }
.accent-2e7d4f { --accent: #2e7d4f; } .accent-127a70 { --accent: #127a70; } .accent-a23b5a { --accent: #a23b5a; }
.shop-tag { display: inline-grid; place-items: center; min-width: 22px; height: 28px; padding: 0 4px; border-radius: 4px; background: var(--accent, #1d5fa8); border: 2px solid #e9cf86; color: #fff; font-size: 12px; font-weight: 800; line-height: 1; }
.scope-bar { display: flex; align-items: center; gap: 10px; padding: 8px 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
.scope-label { font-size: 12px; font-weight: 600; color: var(--muted); flex: none; }
.scope-options { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.scope-options::-webkit-scrollbar { display: none; }
.scope-option { flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: 14px; color: var(--ink); cursor: pointer; }
.scope-option i { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.scope-option[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; font-weight: 600; }
.shop-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin-bottom: 14px; }
.shop-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); text-align: left; cursor: pointer; }
.shop-card:hover { border-color: var(--teal); }
.shop-card > span { flex: 1; display: grid; }
.shop-card strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.shop-card small { font-size: 12px; color: var(--muted); }
.shop-card .shop-tag { width: 30px; height: 40px; font-size: 16px; }
.shop-card i { font-style: normal; color: var(--muted); font-size: 20px; }
.ledger.with-shop .ledger-head, .ledger.with-shop .ledger-row { grid-template-columns: 34px 104px minmax(0, 1.5fr) minmax(0, 1.5fr) 72px 128px 64px; }
.detail-tags { display: flex; align-items: center; gap: 6px; }
.set-chip.is-off { opacity: .6; text-decoration: line-through; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin-bottom: 18px; }
.shop-item { display: grid; gap: 12px; align-content: start; }
.shop-item.is-closed { opacity: .8; }
.shop-item-head { display: flex; align-items: center; gap: 12px; }
.shop-item-head > div { flex: 1; display: grid; }
.shop-item-head h2 { font-size: 17px; }
.shop-item-head a { font-size: 13px; }
.shop-item-head .shop-tag { width: 36px; height: 48px; font-size: 20px; }
.shop-item .facts dd { display: flex; flex-wrap: wrap; gap: 4px; }
.shop-add { min-height: 160px; border: 1.5px dashed #9fb2bb; border-radius: var(--radius); background: transparent; display: grid; place-content: center; gap: 4px; font-weight: 600; color: var(--muted); cursor: pointer; }
.shop-add span { font-size: 28px; line-height: 1; }
.shop-add:hover { border-color: var(--teal); color: var(--teal-ink); }
.shop-form { display: grid; gap: 16px; max-width: 760px; }
.shop-form fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 8px; }
.shop-form legend { font-size: 13px; font-weight: 600; padding: 0; margin-bottom: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.url-field { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.url-field > span { display: grid; place-items: center; padding: 0 10px; background: var(--line-2); color: var(--muted); font-size: 13px; font-weight: 400; }
.url-field input { flex: 1; min-width: 0; border: 0; border-radius: 0; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { position: relative; width: 38px; height: 38px; border-radius: 50%; background: var(--accent); cursor: pointer; }
.swatch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.swatch:has(input:checked) { box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--navy); }
.swatch:focus-within { outline: 3px solid #127a7055; outline-offset: 4px; }
.choice-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-size: 14px; }
.choice-row:has(input:checked) { border-color: var(--teal); background: var(--teal-soft); }
.choice-row span { display: grid; }
.choice-row small { font-size: 12px; color: var(--muted); }
.choice-row input { width: auto; min-height: 0; flex-shrink: 0; margin-top: 4px; accent-color: var(--teal); }
.product-list-edit { display: grid; gap: 6px; }
.product-edit { display: grid; grid-template-columns: minmax(0, 1fr) auto 96px; gap: 8px; align-items: center; }
.product-edit input[readonly] { background: var(--line-2); }
.product-edit .muted { text-align: center; }
@media (max-width: 860px) {
  .held-group li { flex-direction: column; align-items: stretch; }
  .row-buttons .btn { flex: 1; }
}
@media (max-width: 860px) {
  .nav { grid-template-columns: repeat(7, 1fr); }
  .nav a { font-size: 10px; padding: 6px 0; }
  .scope-bar { padding: 8px 16px; }
  .ledger.with-shop .ledger-row { grid-template-columns: 30px minmax(0, 1fr) auto; grid-template-areas: "shop name total" "shop items items" "shop date source"; }
  .ledger.with-shop .cell-shop { grid-area: shop; align-self: start; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .product-edit { grid-template-columns: minmax(0, 1fr) auto 44px; }
  .product-edit .muted { display: none; }
}

.rp-grid input[type=date] { min-height: 38px; padding: 6px 10px; font-size: 14px; }
.rp-range { margin: 2px 0 0; }
.rp-range span { font-weight: 600; color: var(--ink); }
