:root {
  --bg: #f4f6f9; --panel: #fff; --ink: #1d2433; --muted: #6b7385; --line: #e3e7ee;
  /* theme colours (overridden per viewer by applyTheme in app.js; default = green) */
  --brand: #1e8a4c; --brand-dark: #16703c; --brand-soft: #e5f4eb;
  --side: #0f3a24; --side-hover: #17502f; --side-on: #21693e; --side-ink: #cfe6d8; --side-muted: #86b39a;
  --info: #1f5fbf; --info-soft: #e8f0fc; --red: #c8352b; --red-soft: #fdecea;
  --amber: #b26a00; --amber-soft: #fff4e0; --green: #1e8a4c; --green-soft: #e6f5ec;
  --purple: #6a43b8; --purple-soft: #f0eafb;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 'IBM Plex Sans Thai', 'Segoe UI', Tahoma, sans-serif; }
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mono { font-family: Consolas, monospace; font-size: 12.5px; }

/* layout */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.side .logo { color: #fff; font-weight: 700; font-size: 16px; padding: 4px 8px 14px; }
.side .logo small { display: block; font-weight: 400; color: var(--side-muted); font-size: 12px; }
.side a { display: flex; justify-content: space-between; color: var(--side-ink); padding: 8px 10px; border-radius: 6px; margin: 1px 0; }
.side a:hover { background: var(--side-hover); }
.side a.on { background: var(--side-on); color: #fff; }
.side .sec { color: var(--side-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; padding: 12px 10px 4px; }
.side .badge { background: var(--red); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11.5px; line-height: 20px; }
.side .me { border-top: 1px solid var(--side-hover); margin-top: 14px; padding: 12px 10px 0; font-size: 12.5px; }
.side .me b { color: #fff; display: block; }
.main { padding: 20px 24px 40px; min-width: 0; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; cursor: pointer; }
.kpi:hover { border-color: var(--brand); }
.kpi .t { color: var(--muted); font-size: 12.5px; }
.kpi .v { font-size: 26px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--red); }
.kpi.ok .v { color: var(--green); } .kpi.over .v { color: var(--red); } .kpi.nopic .v { color: var(--amber); } .kpi.pend .v { color: var(--info); }

/* filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 5px 12px; cursor: pointer; color: var(--ink); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--brand); color: #fff; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  border: 1px solid #cfd6e2; border-radius: 7px; padding: 6px 9px; background: #fff; color: var(--ink); }
textarea { width: 100%; resize: vertical; }
label.chk { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.btn { border: 1px solid #cfd6e2; background: #fff; border-radius: 7px; padding: 6px 13px; cursor: pointer; color: var(--ink); }
.btn:hover { border-color: var(--brand); }
.btn.pri { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.pri:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 2px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 3px 11px; cursor: pointer; font-size: 13px; }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.chip b { margin-left: 4px; }

/* tables */
.tw { overflow: auto; border: 1px solid var(--line); border-radius: 8px; max-height: 70vh; }
table { border-collapse: collapse; width: 100%; background: #fff; }
th, td { padding: 6px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f7f9fc; font-weight: 600; font-size: 12.5px; color: #3c4558; position: sticky; top: 0; z-index: 1; white-space: nowrap; }
tbody tr:hover td { background: #fafcff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.sub td { background: #fbfcfe; }
tr.click { cursor: pointer; }
.zero { color: #c3c9d4; }

.tag { display: inline-block; border-radius: 5px; padding: 0 7px; font-size: 12px; line-height: 20px; white-space: nowrap; background: #eef1f6; color: #3c4558; }
.tag.red { background: var(--red-soft); color: var(--red); }
.tag.amber { background: var(--amber-soft); color: var(--amber); }
.tag.green { background: var(--green-soft); color: var(--green); }
.tag.blue { background: var(--info-soft); color: var(--info); }
.tag.purple { background: var(--purple-soft); color: var(--purple); }

.deptcard h3 { display: flex; justify-content: space-between; align-items: baseline; }
.deptcard h3 a { color: var(--ink); }
.deptcard .big { font-size: 22px; font-weight: 700; }
.bar { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-top: 1px dashed var(--line); cursor: pointer; }
.bar:hover { color: var(--brand); }

/* review */
.rv { display: flex; flex-wrap: wrap; gap: 6px; }
.rv label { border: 1px solid var(--line); border-radius: 7px; padding: 4px 10px; cursor: pointer; background: #fff; }
.rv input { margin-right: 5px; }
.rv label.on-OK { border-color: var(--green); background: var(--green-soft); }
.rv label.on-OVER { border-color: var(--red); background: var(--red-soft); }
.rv label.on-NOPIC { border-color: var(--amber); background: var(--amber-soft); }
.detail { padding: 10px 6px; }
.detail table th { position: static; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 4px 16px; margin-bottom: 10px; font-size: 13px; }
.kv span { color: var(--muted); }

/* login */
.login { max-width: 360px; margin: 12vh auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 28px; }
.login h1 { margin-bottom: 2px; }
.login label { display: block; margin: 14px 0 4px; font-weight: 500; }
.login input { width: 100%; padding: 9px 11px; }
.login .btn { width: 100%; margin-top: 18px; padding: 9px; }
.err { color: var(--red); margin-top: 10px; min-height: 20px; }

.form-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 10px; }
.form-row > label { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--muted); }
pre.json { background: #0f1b30; color: #cfe0ff; padding: 10px; border-radius: 8px; max-height: 320px; overflow: auto; font-size: 12px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1d2433; color: #fff; padding: 9px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.bad { background: var(--red); }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .main { padding: 14px 12px 30px; }
}
.photos { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.photos img { width: 92px; height: 92px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; }
.photos .vid { width: 92px; height: 92px; border-radius: 6px; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; background: #f7f9fc; font-size: 12.5px; }
td.link { cursor: pointer; color: var(--brand); }
td.link:hover { background: var(--brand-soft) !important; text-decoration: underline; }
.kpi[data-go], .tag[data-go] { cursor: pointer; }
.photos img { cursor: zoom-in; }
#viewer { display: none; position: fixed; inset: 0; background: rgba(8, 12, 22, .92); z-index: 100; }
#viewer.show { display: block; }
.vw-bar { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; color: #fff; z-index: 2; }
.vw-btn { background: rgba(255,255,255,.12); border: 0; color: #fff; font-size: 20px; width: 42px; height: 42px; border-radius: 8px; margin-left: 6px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.vw-btn:hover { background: rgba(255,255,255,.25); }
.vw-stage { position: absolute; inset: 62px 70px 20px; display: flex; align-items: center; justify-content: center; }
#vw-img { max-width: 100%; max-height: 100%; transition: transform .2s; box-shadow: 0 4px 30px rgba(0,0,0,.5); }
#vw-img.side { max-width: calc(100vh - 82px); max-height: calc(100vw - 140px); }
.vw-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.12); border: 0; color: #fff; font-size: 40px; width: 52px; height: 80px; border-radius: 10px; cursor: pointer; z-index: 2; }
.vw-nav:hover { background: rgba(255,255,255,.25); }
.vw-nav.prev { left: 10px; } .vw-nav.next { right: 10px; }
.panel.loan.focus { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }

/* parts table: highlight ใช้ / ขาย / คงค้าง */
.parts th.hcol { color: var(--ink); }
.parts th.used { background: var(--info-soft); } .parts th.sold { background: #e6f5ec; } .parts th.out { background: #fff4e0; }
.parts td.used { background: #f5f8fe; } .parts td.sold { background: #f3faf6; } .parts td.out { background: #fffaf0; }
.hl { display: inline-block; min-width: 26px; text-align: center; font-weight: 700; border-radius: 5px; padding: 0 6px; line-height: 21px; font-size: 13.5px; }
.hl.used { background: var(--info); color: #fff; }
.hl.sold { background: var(--green); color: #fff; }
.hl.out { background: var(--amber); color: #fff; }
.hl.over { background: var(--red); color: #fff; }
.parts tr.moved td:nth-child(2) { font-weight: 600; }

/* sortable headers */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--brand); }

/* reviewed rows: green + struck through */
tr.reviewed td { background: #e3f4ea !important; color: #4d6b58; text-decoration: line-through; text-decoration-color: rgba(30,138,76,.6); }
tr.reviewed td.nostrike { text-decoration: none; }
tr.reviewed td a { color: #4d6b58; }

/* popup */
#modal { position: fixed; inset: 0; background: rgba(15, 22, 38, .55); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.m-box { background: #fff; border-radius: 12px; width: min(1180px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 12px 50px rgba(0,0,0,.3); }
.m-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 15px; }
.m-x { border: 0; background: #eef1f6; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 16px; flex: none; }
.m-x:hover { background: #dfe4ec; }
.m-body { padding: 14px 16px; overflow: auto; flex: 1; min-height: 0; }
.m-foot { padding: 12px 16px; border-top: 1px solid var(--line); background: #f7f9fc; border-radius: 0 0 12px 12px; }
.flash { position: fixed; top: 40%; left: 50%; transform: translate(-50%, -50%) scale(1); background: var(--green); color: #fff; padding: 18px 30px; border-radius: 14px; font-size: 20px; font-weight: 700; text-align: center; z-index: 120; box-shadow: 0 10px 40px rgba(0,0,0,.25); transition: opacity .35s, transform .35s; }
.flash span { font-size: 14px; font-weight: 500; opacity: .9; }
.flash.red { background: var(--red); } .flash.amber { background: var(--amber); }
.flash.out { opacity: 0; transform: translate(-50%, -50%) scale(.92); }
.sbar { height: 10px; background: #eef1f6; border-radius: 5px; overflow: hidden; }
.sbar span { display: block; height: 100%; background: var(--brand); border-radius: 5px; }
tfoot th { position: static; background: #f7f9fc; }

/* Keen Eye branding + theme picker */
.eye { color: var(--brand); filter: brightness(1.4); }
.side .logo .eye { color: #fff; opacity: .9; }
.en { font-weight: 500; font-size: .7em; opacity: .75; letter-spacing: .03em; }
.themes { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.themes .dot { width: 20px; height: 20px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35); cursor: pointer; padding: 0; }
.themes .dot.on { border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,.35); }
.btn.warn { border-color: var(--red); color: var(--red); }
.kv .wide { grid-column: 1 / -1; }
td.symptom { max-width: 260px; font-size: 12.5px; color: #3c4558; }
.jm { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 6px 16px; }
.jm label { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-bottom: 1px dashed var(--line); padding: 3px 0; }
.upl { border: 1px dashed var(--line); border-radius: 8px; padding: 8px 10px; margin-top: 4px; }
input.ack { width: 18px; height: 18px; cursor: pointer; accent-color: var(--green); }
.login h1 .en { color: var(--muted); }
.alertbar { background: var(--red-soft); border: 1px solid #f3b8b2; color: #7a1f17; border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 13.5px; }
.alertbar a { color: var(--red); font-weight: 600; text-decoration: underline; }
