:root {
  --bg: #F4F3F0; --surface: #fff; --ink: #1C1C1E; --muted: #4A4D52; --line: #E2E0DB; --line2: #EEECE7;
  --input: #D6D3CC; --accent: #C8102E; --accent-ink: #8A0B1F; --accent-soft: #FBF3F4; --side: #1E2124;
  --ok-bg: #E7F3EC; --ok: #1E5B3A; --warn-bg: #FFF1D6; --warn: #8A4B00; --bad-bg: #FBE3E7; --bad: #8A0B1F;
  --info-bg: #E6EEF9; --info: #1D4E89;
  --font: 'IBM Plex Sans Thai', 'Leelawadee UI', Tahoma, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; }
a { color: #B00E28; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; color: var(--muted); }
.hidden { display: none !important; }

/* layout */
.shell { display: flex; flex-wrap: wrap; min-height: 100vh; }
.side { flex: 1 1 220px; max-width: 250px; background: var(--side); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; }
.side .logo { background: #fff; border-radius: 10px; padding: 10px; margin-bottom: 14px; }
.side .logo img { display: block; width: 100%; height: auto; }
.nav { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 12px; border-radius: 8px; color: #D9DBDE; text-decoration: none; }
.nav:hover { background: #2C3035; color: #fff; }
.nav.on { background: var(--accent); color: #fff; font-weight: 600; }
.nav .grow { flex: 1; }
.badge-warn { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: #F5A623; color: #1C1C1E; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.side-foot { margin-top: auto; padding: 12px; border-top: 1px solid #383C42; font-size: 13px; color: #B9BCC1; display: flex; flex-direction: column; gap: 4px; }
.side-foot button { background: none; border: 1px solid #4A4F57; color: #D9DBDE; border-radius: 8px; min-height: 36px; cursor: pointer; }
.main { flex: 999 1 560px; min-width: 0; padding: 22px 26px 60px; display: flex; flex-direction: column; gap: 18px; }

/* typography & blocks */
h1 { margin: 0; font-size: 25px; font-weight: 700; }
h2 { margin: 0; font-size: 17px; font-weight: 600; }
h3 { margin: 0; font-size: 15px; font-weight: 600; }
.sub { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.top { align-items: flex-start; }
.grow { flex: 1 1 auto; }
.cols { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.col-main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.col-side { flex: 1 1 380px; max-width: 520px; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.grid { display: grid; gap: 12px 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; } .span3 { grid-column: span 3; } .spanall { grid-column: 1 / -1; }
@media (max-width: 760px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .span3 { grid-column: span 2; } .main { padding: 16px; } }

/* forms */
label.lbl, .lbl { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 5px; }
.inp { width: 100%; height: 42px; border: 1px solid var(--input); border-radius: 8px; padding: 0 11px; background: #fff; font-size: 15px; }
textarea.inp { height: auto; min-height: 70px; padding: 9px 11px; }
.inp:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px #FBE3E7; }
.inp.sm { height: 36px; }
.inp.num { text-align: right; }
.inp[readonly] { background: #F7F6F3; }
.btn { height: 42px; padding: 0 16px; border-radius: 8px; border: 1px solid #C9C5BD; background: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; }
.btn:hover { border-color: #9E9A92; }
a.btn { text-decoration: none; color: inherit; }
a.btn.primary { color: #fff; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #A90D27; }
.btn.dark { background: var(--side); border-color: var(--side); color: #fff; font-weight: 600; }
.btn.ghost { border-color: transparent; background: none; color: var(--accent-ink); font-weight: 500; }
.btn.icon { width: 38px; height: 38px; padding: 0; }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; border: 1px solid #C9C5BD; border-radius: 10px; overflow: hidden; }
.seg button { height: 42px; padding: 0 14px; border: 0; background: #fff; cursor: pointer; font-weight: 500; }
.seg button + button { border-left: 1px solid #C9C5BD; }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }
.chip { height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--input); background: #fff; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; }
.chip.on { border: 2px solid var(--accent); background: var(--accent-soft); font-weight: 600; }
.chip.dark.on { background: var(--side); color: #fff; border-color: var(--side); }
.dot { width: 24px; height: 24px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; cursor: pointer; }
.check input { width: 19px; height: 19px; accent-color: var(--accent); }

/* tags & notices */
.tag { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 500; white-space: nowrap; }
.t-part { background: #F3EEE4; color: #6B4A12; } .t-labor { background: var(--info-bg); color: var(--info); }
.t-fluid { background: var(--ok-bg); color: var(--ok); } .t-tune { background: #F1E8F6; color: #5B2A7A; } .t-other { background: #F1F0EC; color: var(--muted); }
.t-ok { background: var(--ok-bg); color: var(--ok); } .t-low { background: var(--warn-bg); color: var(--warn); } .t-out { background: var(--bad-bg); color: var(--bad); } .t-none { background: #F1F0EC; color: var(--muted); }
.notice { padding: 10px 14px; border-radius: 10px; font-size: 14px; }
.notice.info { background: var(--info-bg); color: var(--info); }
.notice.warn { background: var(--warn-bg); color: #5C3300; border: 1px solid #F2CF8C; }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }

/* tables */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { font-size: 12px; font-weight: 600; color: var(--muted); text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); background: #FAFAF8; white-space: nowrap; }
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: #FBFAF7; }
.tbl tr.sel td { background: var(--accent-soft); }
.tbl tr.void td { color: #8B8E93; text-decoration: line-through; }
.r { text-align: right; } .c { text-align: center; } .b { font-weight: 600; } .nw { white-space: nowrap; }
.items td { padding: 5px 6px; }
.items .inp { height: 36px; }

/* autocomplete */
.ac { position: relative; }
.ac-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 28px rgba(0,0,0,.12); overflow: hidden; max-height: 340px; overflow-y: auto; }
.ac-item { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; padding: 9px 13px; cursor: pointer; border-top: 1px solid var(--line2); width: 100%; text-align: left; background: #fff; border-left: 0; border-right: 0; border-bottom: 0; }
.ac-item:first-child { border-top: 0; }
.ac-item:hover, .ac-item.hl { background: var(--accent-soft); }
.ac-new { color: #B00E28; font-weight: 500; font-size: 14px; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 15px; }
.tile .v { font-size: 26px; font-weight: 700; }

/* totals */
.totals { text-align: right; }
.totals .big { font-size: 36px; font-weight: 700; line-height: 1.15; }

/* preview */
.preview-box { background: #E9E7E2; border-radius: 8px; padding: 12px 0; display: flex; flex-direction: column; align-items: center; gap: 10px; max-height: 760px; overflow: auto; }
.preview-scale { transform-origin: top left; }
.preview-scale .rc-page { box-shadow: 0 2px 10px rgba(0,0,0,.15); margin-bottom: 8mm; }

/* modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(20,20,22,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 14px; padding: 20px 22px; width: min(520px, 100%); display: flex; flex-direction: column; gap: 14px; max-height: 92vh; overflow: auto; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--side); color: #fff; padding: 11px 18px; border-radius: 10px; z-index: 200; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 90vw; }
.toast.bad { background: var(--bad); }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login .card { width: min(400px, 100%); }

/* ============ receipt (A4) ============ */
#print-root { display: none; }
.rc-page {
  width: 210mm; height: 297mm; padding: 8mm 10mm; background: #fff; color: #111; overflow: hidden;
  font-family: 'Sarabun', 'Leelawadee UI', Tahoma, sans-serif; font-size: 10.5pt; line-height: 1.25;
  display: flex; flex-direction: column; gap: 2mm; position: relative;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.rc-page * { box-sizing: border-box; }
.rc-head { display: flex; gap: 4mm; align-items: flex-start; height: 35mm; flex-shrink: 0; }
.rc-head-l { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1mm; }
.rc-header-img { width: 128mm; max-height: 34mm; object-fit: contain; object-position: left top; }
.rc-logo { width: 55mm; height: auto; margin-top: 1mm; }
.rc-taxline { font-weight: 600; height: 5mm; }
.rc-titlebar { display: flex; align-items: flex-end; gap: 4mm; height: 12mm; flex-shrink: 0; }
.rc-title-l { flex: 1; display: flex; align-items: center; gap: 4mm; min-width: 0; }
.rc-title { font-size: 21pt; font-weight: 700; color: #C8102E; white-space: nowrap; }
.rc-badge { border: 2px solid #C8102E; color: #C8102E; font-weight: 700; font-size: 12pt; padding: 0.3mm 4mm; border-radius: 1mm; }
.rc-badge-copy { border-color: #555; color: #444; }
.rc-meta { width: 66mm; display: flex; flex-direction: column; gap: 1mm; }
.rc-meta > div { display: flex; gap: 2mm; align-items: baseline; }
.rc-meta .rc-k { width: 11mm; text-align: right; }
.rc-pageno { white-space: nowrap; }
.rc-cust { display: flex; flex-direction: column; flex-shrink: 0; }
.rc-line { display: flex; gap: 2mm; align-items: baseline; height: 6.5mm; }
.rc-k { font-weight: 600; white-space: nowrap; }
.rc-v { border-bottom: 1px dotted #555; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 1mm; min-height: 4.6mm; flex: 1; }
.rc-cust .rc-line > .rc-k:first-child { width: 17mm; }
.rc-grow2 { flex: 2; } .rc-grow13 { flex: 1.35; } .rc-grow1 { flex: 1; } .rc-grow07 { flex: .7; } .rc-grow05 { flex: .5; } .rc-grow03 { flex: .3; }
.rc-center { text-align: center; }
.rc-table { flex: 1; min-height: 0; border: 1px solid #111; display: flex; flex-direction: column; }
.rc-th, .rc-tr, .rc-fill, .rc-fwd, .rc-sum, .rc-total { display: flex; }
.rc-th { height: 7mm; align-items: stretch; font-weight: 700; text-align: center; background: #F0F0F0; border-bottom: 1px solid #111; flex-shrink: 0; }
.rc-th .rc-c { display: flex; align-items: center; justify-content: center; }
.rc-tr { height: 6.3mm; border-bottom: 1px solid #C4C4C4; flex-shrink: 0; }
.rc-c { border-right: 1px solid #111; padding: 0 1.5mm; display: flex; align-items: center; min-width: 0; white-space: nowrap; overflow: hidden; }
.rc-c:last-child { border-right: 0; }
.rc-qty { width: 14mm; flex-shrink: 0; justify-content: center; }
.rc-desc { flex: 1; overflow: hidden; text-overflow: ellipsis; display: block; line-height: 6.1mm; }
.rc-tech { width: 21mm; flex-shrink: 0; justify-content: center; font-size: 9pt; }
.rc-num { width: 24mm; flex-shrink: 0; justify-content: flex-end; }
.rc-amt { width: 28mm; flex-shrink: 0; justify-content: flex-end; }
.rc-th .rc-num, .rc-th .rc-amt, .rc-th .rc-qty, .rc-th .rc-tech { justify-content: center; }
.rc-fill { flex: 1; min-height: 0; }
.rc-fwd { height: 7mm; font-weight: 700; background: #F7F7F7; border-bottom: 1px solid #111; flex-shrink: 0; }
.rc-fwd-l { flex: 1; }
.rc-sum { height: 6mm; flex-shrink: 0; border-top: 1px solid #C4C4C4; }
.rc-sum-first { border-top: 1px solid #111; }
.rc-sum-pad { flex: 1; }
.rc-sum-l { width: 45mm; flex-shrink: 0; justify-content: center; }
.rc-total { height: 8mm; flex-shrink: 0; border-top: 1px solid #111; font-weight: 700; }
.rc-words { flex: 1; justify-content: center; }
.rc-grand { font-size: 12pt; }
.rc-carry { background: #F7F7F7; }
.rc-pay { height: 31mm; flex-shrink: 0; border: 1px solid #111; display: flex; gap: 4mm; align-items: center; padding: 2mm 3mm; }
.rc-pay-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2mm; }
.rc-pay-row { display: flex; flex-wrap: wrap; gap: 2mm 5mm; align-items: baseline; }
.rc-sign { margin-top: 1.5mm; }
.rc-dot { border-bottom: 1px dotted #555; padding: 0 2mm; font-weight: 600; }
.rc-bank { font-weight: 700; }
.rc-qr { width: 22mm; height: 27mm; object-fit: contain; }

@page { size: A4; margin: 0; }
@media print {
  html, body { background: #fff; }
  #app, .toast, .modal-back { display: none !important; }
  #print-root { display: block !important; }
  #print-root .rc-page { break-after: page; page-break-after: always; }
  #print-root .rc-page:last-child { break-after: auto; page-break-after: auto; }
}
@media (max-width: 760px) {
  .side { max-width: none; flex-direction: row; flex-wrap: nowrap; overflow-x: auto; padding: 8px; gap: 4px; position: sticky; top: 0; z-index: 20; }
  .nav { white-space: nowrap; flex: 0 0 auto !important; }
  .side .logo, .side-foot { display: none; }
  .nav { flex: 1 1 auto; min-height: 40px; padding: 0 10px; font-size: 14px; }
}

/* ===== ใบรับรถ ===== */
.ri-page { gap: 3mm; }
.ri-fuel { display: flex; gap: 5mm; align-items: center; flex-shrink: 0; }
.ri-f.on { font-weight: 700; }
.ri-box { border: 1px solid #111; flex-shrink: 0; }
.ri-box-h { background: #F0F0F0; border-bottom: 1px solid #111; padding: 1mm 2mm; font-weight: 700; }
.ri-box-b { padding: 2mm; line-height: 1.5; white-space: normal; }
.ri-two { display: flex; gap: 3mm; } .ri-two .ri-box { flex: 1; min-width: 0; }
.ri-photos { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 3mm; align-items: start; }
.ri-photos figure { margin: 0; border: 1px solid #999; padding: 1mm; }
.ri-photos img { width: 100%; height: 40mm; object-fit: cover; display: block; }
.ri-photos figcaption { text-align: center; font-size: 9pt; }
.ri-photos-empty { flex: 1; }
.ri-note { font-size: 9.5pt; border-top: 1px dashed #777; padding-top: 2mm; flex-shrink: 0; }
.ri-sign { display: flex; gap: 20mm; justify-content: space-around; text-align: center; padding: 6mm 0 2mm; flex-shrink: 0; }
.ri-sign > div { flex: 1; }
.ri-line { border-bottom: 1px dotted #333; height: 12mm; margin-bottom: 1.5mm; }

/* ===== รับรถ (มือถือ) ===== */
.intake { max-width: 720px; display: flex; flex-direction: column; gap: 14px; }
.shot { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.shot-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 18px; border-radius: 10px; border: 2px dashed #C9C5BD; background: #fff; cursor: pointer; font-weight: 600; }
.shot-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumb { position: relative; width: 92px; height: 92px; border-radius: 8px; overflow: hidden; border: 1px solid #E2E0DB; background: #F7F6F3; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .k { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 11px; text-align: center; }
.thumb button { position: absolute; top: 2px; right: 2px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }
.fuel { display: flex; gap: 6px; flex-wrap: wrap; }
.fuel button { min-width: 56px; height: 44px; border-radius: 8px; border: 1px solid #C9C5BD; background: #fff; font-weight: 600; cursor: pointer; }
.fuel button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.draft-card { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; flex-wrap: wrap; }
.draft-card img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; background: #F7F6F3; }
.draft-strip { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
