:root {
  --bg: #f4f7f8;
  --card: #ffffff;
  --text: #17212b;
  --muted: #5d6877;
  --line: #dbe2e8;
  --brand: #12a3a6;
  --brand-dark: #1d3f73;
  --ok: #1a8f4c;
  --bad: #c0392b;
  --warn-bg: #fff4e0;
  --warn: #8a5300;
  --chip: #e8f6f6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12171c; --card: #1b2229; --text: #e6ebf0; --muted: #9aa6b2; --line: #2f3a45;
    --chip: #183338; --warn-bg: #3a2c12; --warn: #f0c36b;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 "Prompt", "Sarabun", system-ui, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { width: 100%; padding: 8px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
label { display: block; color: var(--muted); font-size: .88rem; margin-top: 8px; }
label > input, label > select, label > textarea { margin-top: 3px; color: var(--text); }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.btn { padding: 9px 16px; border: 1px solid var(--line); border-radius: 9px; background: var(--card); cursor: pointer; font-weight: 500; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { background: var(--card); border-color: var(--bad); color: var(--bad); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* เข้าสู่ระบบ */
.auth { max-width: 380px; margin: 8vh auto; padding: 0 16px; }
.auth .card { padding: 24px; }
.auth .logo { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.auth .logo img { width: 56px; height: 56px; border-radius: 14px; object-fit: cover; }
.qr { display: block; margin: 12px auto; width: 200px; height: 200px; background: #fff; border-radius: 8px; }
.secret { font-family: ui-monospace, monospace; word-break: break-all; background: var(--bg); padding: 6px 8px; border-radius: 6px; }

/* โครงหน้า */
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--brand-dark); color: #fff; flex-wrap: wrap; }
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.topbar .brand img { width: 34px; height: 34px; border-radius: 9px; background: #fff; object-fit: cover; }
.topbar select { width: auto; min-width: 220px; background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.25); }
.topbar select option { color: #17212b; }
.topbar .me { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.topbar .me .btn { padding: 5px 10px; background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.tabs { display: flex; gap: 4px; padding: 0 20px; background: var(--card); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { padding: 12px 14px; border: 0; border-bottom: 3px solid transparent; background: none; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tab.active { color: var(--text); border-bottom-color: var(--brand); font-weight: 600; }
.tab .count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 10px; background: var(--brand); color: #fff; font-size: .78rem; }
main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.demo-banner { background: var(--warn-bg); color: var(--warn); text-align: center; padding: 6px; font-size: .88rem; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--brand-dark); color: #fff;
  padding: 10px 18px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.2); z-index: 10; }
.error { color: var(--bad); }

/* รายการขายรออนุมัติ */
.sales { display: grid; gap: 12px; }
.sale-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.chip { display: inline-block; padding: 2px 10px; border-radius: 12px; background: var(--chip); font-size: .82rem; }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.ok { background: #e3f5ea; color: var(--ok); }
.chip.bad { background: #fbe7e5; color: var(--bad); }
table { width: 100%; border-collapse: collapse; margin-top: 10px; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: .85rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 600; border-top: 2px solid var(--line); }

/* ตรวจรายจ่าย */
.review { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; }
.review .list { padding: 0; max-height: calc(100vh - 190px); overflow: auto; }
.filter { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); }
.filter .btn { padding: 5px 10px; font-size: .85rem; }
.filter .btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.item { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:hover { background: var(--bg); }
.item.active { background: var(--chip); }
.item .line1 { display: flex; justify-content: space-between; gap: 8px; }
.item .line2 { color: var(--muted); font-size: .85rem; }
.detail { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(320px, .9fr); gap: 16px; }
.viewer { background: var(--bg); border-radius: 10px; min-height: 560px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.viewer img { max-width: 100%; max-height: 75vh; }
.viewer iframe { width: 100%; height: 75vh; border: 0; }
.fields .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.warnbox { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 8px 10px; margin-top: 8px; font-size: .9rem; }

/* รายงาน */
.report-bar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.report-bar label { margin: 0; }
.report-bar select, .report-bar input { width: auto; }
.report-head { margin: 16px 0 4px; line-height: 1.8; }

@media (max-width: 1000px) {
  .review, .detail { grid-template-columns: 1fr; }
  .review .list { max-height: 320px; }
}

/* พนักงาน */
.btn.small { padding: 4px 10px; font-size: .85rem; }
.small { font-size: .85rem; }
.staff-form, .notice { margin-bottom: 16px; }
.notice { border-color: var(--brand); }
.notice pre { white-space: pre-wrap; margin: 10px 0 0; font-size: .9rem; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 2px 12px; margin-top: 6px; }
label.check { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: .92rem; margin-top: 6px; cursor: pointer; }
label.check input { width: auto; margin: 0; }
tr.muted td { color: var(--muted); }

/* ลืมรหัสผ่าน */
.auth-links { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.link { background: none; border: 0; padding: 0; color: var(--brand); cursor: pointer; font-size: .9rem; }
.link:hover { text-decoration: underline; }
.notice-box { background: var(--chip); border-radius: 8px; padding: 10px 12px; margin-top: 12px; line-height: 1.6; }

/* ลูกค้า */
.staff-form .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.rows { display: grid; gap: 6px; margin-top: 6px; }
.row { display: grid; gap: 6px; align-items: center; }
.row.acc { grid-template-columns: 110px 1fr 1.3fr auto; }
.row.prod { grid-template-columns: 110px 1.6fr 80px 120px auto auto; }
.row label.check { margin: 0; white-space: nowrap; }
.link-code { font: 600 2rem/1.2 ui-monospace, monospace; letter-spacing: .2em; margin: 8px 0; color: var(--brand-dark); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .link-code { color: var(--brand); } }
@media (max-width: 760px) {
  .row.acc, .row.prod { grid-template-columns: 1fr 1fr; }
  .fields .grid2, .grid2 { grid-template-columns: 1fr; }
}
