:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --border: #dde1e6;
  --border-strong: #c4cad2;
  --text: #1c2229;
  --text-2: #56606c;
  --text-3: #6b7480;
  --accent: #0d7377;
  --accent-hover: #0a5d61;
  --accent-soft: #e3f3f3;
  --ok: #1a7f4b;      --ok-soft: #e4f4ea;
  --warn: #a15c00;    --warn-soft: #fff1d6;  --warn-line: #e39a12;
  --bad: #b3261e;     --bad-soft: #fde8e6;   --bad-line: #d9483f;
  --edit: #2358d4;    --edit-soft: #e5ecfc;  --edit-line: #3f74ec;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(20, 30, 40, .06);
  --font: "Noto Sans Thai", "Sarabun", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 400 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.3; }
h1 { font-size: 24px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
p { margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--text-2); } .small { font-size: 13px; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-in { max-width: 1800px; margin: 0 auto; height: 56px; padding: 0 24px; display: flex; align-items: center; gap: 24px; }
.brand { font-weight: 700; font-size: 16px; color: var(--accent); text-decoration: none; white-space: nowrap; }
.doc-title { flex: 1; min-width: 0; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-title b { color: var(--text); font-weight: 500; }
.stepper { display: flex; align-items: center; gap: 8px; }
.step { display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: 999px; font-size: 14px; color: var(--text-3);
  background: none; border: 0; cursor: default; white-space: nowrap; }
.step .dot { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 600;
  border: 1.5px solid var(--border-strong); background: var(--surface); color: var(--text-3); }
.step.go { color: var(--text-2); cursor: pointer; } .step.go:hover { background: var(--surface-2); }
.step.done { color: var(--text-2); }
.step.done .dot { background: var(--accent); border-color: var(--accent); color: #fff; }
.step.current { color: var(--text); font-weight: 600; background: var(--accent-soft); }
.step.current .dot { background: var(--accent); border-color: var(--accent); color: #fff; }
.step-sep { width: 16px; height: 1px; background: var(--border-strong); }

main { outline: none; }
.page { max-width: 1600px; margin: 0 auto; padding: 32px 24px 48px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 24px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: var(--surface); font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none; color: var(--text); }
.btn:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--accent-hover); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 14px; }
.btn.icon { width: 32px; padding: 0; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
.btn.toggle-on { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }

/* upload */
.upload-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(320px, 1fr); gap: 24px; align-items: start; }
.hero { margin-bottom: 24px; } .hero p { margin-top: 8px; color: var(--text-2); max-width: 720px; }
.drop { border: 2px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2); padding: 40px 24px; text-align: center;
  transition: border-color .15s, background .15s; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .big { font-size: 16px; font-weight: 500; margin-bottom: 16px; }
.drop .icon { font-size: 32px; line-height: 1; margin-bottom: 8px; color: var(--accent); }
.filebox { display: flex; align-items: center; gap: 16px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); margin-top: 16px; }
.filebox .fname { font-weight: 600; word-break: break-all; }
.filebox > div:first-child { flex: 1; min-width: 0; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 24px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.input { height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); width: 100%; }
.input:disabled { background: var(--surface-2); color: var(--text-2); }
.hint { font-size: 12px; color: var(--text-3); }
.actions { display: flex; justify-content: flex-end; margin-top: 24px; gap: 8px; }
.error-text { color: var(--bad); font-size: 14px; margin-top: 8px; }
.recent h2 { padding: 16px 24px; border-bottom: 1px solid var(--border); }
.recent-list { list-style: none; margin: 0; padding: 0; max-height: 640px; overflow: auto; }
.recent-item { display: flex; gap: 16px; align-items: center; justify-content: space-between; padding: 12px 24px; width: 100%; text-align: left;
  background: none; border: 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.recent-item:hover { background: var(--surface-2); }
.recent-item .nm { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-item .meta { font-size: 13px; color: var(--text-2); }
.recent-item > div:first-child { min-width: 0; }
.empty { padding: 24px; color: var(--text-2); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--surface-2); color: var(--text-2); }
.pill.running { background: var(--edit-soft); color: var(--edit); }
.pill.review, .pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.exported, .pill.pass { background: var(--ok-soft); color: var(--ok); }
.pill.error, .pill.fail { background: var(--bad-soft); color: var(--bad); }

/* processing */
.proc { max-width: 1100px; margin: 0 auto; }
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 16px 0 8px; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.proc-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.steps { list-style: none; margin: 24px 0 0; padding: 0; }
.steps li { display: flex; align-items: center; gap: 16px; padding: 12px 0; border-top: 1px solid var(--border); }
.steps li:first-child { border-top: 0; }
.sicon { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 13px; font-weight: 700;
  border: 1.5px solid var(--border-strong); color: var(--text-3); }
.sicon.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.sicon.error { background: var(--bad); border-color: var(--bad); color: #fff; }
.sicon.running { border-color: var(--accent); border-top-color: transparent; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.steps .lbl { flex: 1; margin: 0; font-size: 15px; color: var(--text); }
.steps .sec { color: var(--text-2); font-size: 13px; font-variant-numeric: tabular-nums; }
.steps li.pending .lbl { color: var(--text-3); }
.note { margin-top: 16px; padding: 12px 16px; background: var(--surface-2); border-radius: 6px; color: var(--text-2); font-size: 13px; }
.errbox { margin-top: 16px; padding: 16px; background: var(--bad-soft); border: 1px solid var(--bad-line); border-radius: 6px; color: var(--bad); }
.errbox pre { margin: 8px 0 16px; white-space: pre-wrap; font: 13px/1.5 ui-monospace, monospace; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(144px, 1fr)); gap: 16px; margin-top: 24px; }
.thumb { position: relative; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.thumb img { display: block; width: 100%; height: auto; }
.thumb .tag { position: absolute; left: 8px; bottom: 8px; font-size: 12px; background: rgba(255,255,255,.92); border-radius: 4px; padding: 0 8px; }
.thumb .tick { position: absolute; right: 8px; top: 8px; width: 24px; height: 24px; border-radius: 50%; background: var(--ok); color: #fff; display: grid; place-items: center; font-size: 13px; }

/* review */
.review-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr) 328px; gap: 16px; padding: 16px 16px 32px; max-width: 1800px; margin: 0 auto; align-items: start; }
.side, .panel { position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow: auto; }
.side h3, .panel h3 { padding: 12px 16px 8px; font-size: 13px; color: var(--text-2); }
.side ul { list-style: none; margin: 0; padding: 0 8px 8px; }
.side .sec-item, .side .pg-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px; text-align: left; border: 0; background: none; border-radius: 6px; cursor: pointer; font-size: 14px; }
.side .sec-item:hover, .side .pg-item:hover { background: var(--surface-2); }
.side .sec-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .sec-item .p { color: var(--text-3); font-size: 12px; }
.side .pg-item.cur { background: var(--accent-soft); font-weight: 600; }
.side .pg-item .n { flex: 1; }
.side .sec-scroll { max-height: 280px; overflow: auto; border-bottom: 1px solid var(--border); }
.check { color: var(--ok); font-weight: 700; width: 16px; text-align: center; }
.center-head { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.center-head h1 { font-size: 18px; flex: 1; min-width: 200px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.pair.stack { grid-template-columns: 1fr; }
.pane h3 { margin-bottom: 8px; font-size: 14px; }
.imgwrap { position: relative; width: 100%; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.imgwrap.loading::before { content: ""; position: absolute; inset: 0; z-index: 1; background: linear-gradient(90deg, transparent, rgba(255,255,255,.7), transparent); animation: shimmer 1.2s infinite; }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.imgwrap img { display: block; width: 100%; height: 100%; }
.pv { position: absolute; z-index: 1; pointer-events: none; outline: 1.5px dashed var(--accent); outline-offset: 0; background: #fff; }
.pv img { display: block; width: 100%; height: 100%; }
.pv .tag { position: absolute; right: 0; top: 0; padding: 1px 6px; font-size: 10px; line-height: 1.5; color: var(--accent); background: rgba(255, 255, 255, .88); border-bottom-left-radius: 4px; white-space: nowrap; }
.ubox { position: absolute; z-index: 3; box-sizing: border-box; border: 1.5px solid var(--accent); background: rgba(13, 115, 119, .06); cursor: move; touch-action: none; user-select: none; }
.ubox.drag { background: rgba(13, 115, 119, .12); }
.ubox .h { position: absolute; width: 12px; height: 12px; box-sizing: border-box; background: #fff; border: 1.5px solid var(--accent); border-radius: 2px; touch-action: none; }
.ubox .h-nw { left: -7px; top: -7px; cursor: nwse-resize; } .ubox .h-se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.ubox .h-ne { right: -7px; top: -7px; cursor: nesw-resize; } .ubox .h-sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.ubox .h-n { left: calc(50% - 6px); top: -7px; cursor: ns-resize; } .ubox .h-s { left: calc(50% - 6px); bottom: -7px; cursor: ns-resize; }
.ubox .h-w { left: -7px; top: calc(50% - 6px); cursor: ew-resize; } .ubox .h-e { right: -7px; top: calc(50% - 6px); cursor: ew-resize; }
.adj-row.boxrow { display: flex; gap: 10px; flex-wrap: wrap; }
.ov { position: absolute; border: 1px solid rgba(60, 70, 85, .25); border-radius: 2px; cursor: pointer; padding: 0; background: transparent; }
.ov.review { border: 1.5px solid var(--warn-line); background: rgba(227, 154, 18, .12); }
.ov.fail { border: 1.5px solid var(--bad-line); background: rgba(217, 72, 63, .14); }
.ov.edited { border: 1.5px solid var(--edit-line); background: rgba(63, 116, 236, .12); }
.ov:hover, .ov.hover { border-color: var(--accent); background: rgba(13, 115, 119, .22); }
.ov.kept { border: 1px dashed rgba(60, 70, 85, .18); }
.ov.kept:hover, .ov.kept.hover { border: 1px solid var(--accent); }
.ov.deleted { border: 1.5px dashed rgba(60, 70, 85, .55); background: rgba(120, 130, 145, .10);
  background-image: linear-gradient(to top right, transparent calc(50% - 1px), rgba(179, 38, 30, .65) 50%, transparent calc(50% + 1px)); }
.ov.deleted:hover, .ov.deleted.hover { border-color: var(--accent); background-color: rgba(13, 115, 119, .14); }
.drawlayer { position: absolute; inset: 0; z-index: 5; cursor: crosshair; touch-action: none; user-select: none; background: rgba(13, 115, 119, .04); }
.drawrect { position: absolute; box-sizing: border-box; border: 1.5px dashed var(--accent); background: rgba(13, 115, 119, .10); pointer-events: none; }
.banner.draw { display: flex; align-items: center; justify-content: space-between; gap: 16px; background: var(--accent-soft); color: var(--accent); }
.notice { margin: 0; padding: 8px 10px; border-radius: 6px; background: var(--surface-2); font-size: 13px; }
.btn.danger { color: var(--bad); border-color: var(--bad-line); }
.btn.danger:hover:not(:disabled) { background: var(--bad-soft); }
.ov.sel { outline: 2.5px solid var(--accent); outline-offset: 1px; background: rgba(13, 115, 119, .22); z-index: 2; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.panel-body { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 16px; }
.blk-src { padding: 8px 12px; background: var(--surface-2); border-radius: 6px; white-space: pre-wrap; max-height: 120px; overflow: auto; }
.lbl-s { display: block; font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 4px; }
textarea.tgt { width: 100%; min-height: 128px; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: 6px; resize: vertical; line-height: 1.6; background: var(--surface); }
.counter { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-3); margin-top: 4px; }
.counter .over { color: var(--warn); font-weight: 600; }
.notes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.notes li { padding: 8px 12px; border-radius: 6px; background: var(--surface-2); font-size: 13px; }
.notes li b { display: block; font-weight: 600; font-size: 12px; margin-bottom: 2px; }
.notes li.warn { background: var(--warn-soft); } .notes li.bad { background: var(--bad-soft); }
.gl { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.gl div { display: flex; gap: 8px; justify-content: space-between; padding: 4px 8px; background: var(--accent-soft); border-radius: 4px; }
.checkrow { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.checkrow input { width: 16px; height: 16px; accent-color: var(--accent); }
.btnrow { display: flex; gap: 8px; }
.btnrow .btn { flex: 1; padding: 0 8px; }
.phase { font-size: 12px; color: var(--text-3); }
.banner { padding: 12px 16px; border-radius: 6px; background: var(--edit-soft); color: var(--edit); margin-bottom: 16px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.banner.bad { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.banner .progress { margin: 8px 0 0; background: #fff; } .banner.bad { background: var(--bad-soft); color: var(--bad); }
.placeholder { padding: 24px 16px; color: var(--text-2); }
details.pre { font-size: 13px; color: var(--text-2); } details.pre summary { cursor: pointer; }

/* export */
.export { max-width: 880px; margin: 0 auto; }
.sumgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 24px 0; }
.stat { padding: 16px; background: var(--surface-2); border-radius: 6px; }
.stat b { display: block; font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--text-2); }
.export h2 { margin-bottom: 8px; }
.seclist { list-style: none; margin: 8px 0 0; padding: 0; }
.seclist li { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 14px; }
.export-actions { display: flex; gap: 16px; margin-top: 24px; flex-wrap: wrap; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px); background: #1c2229; color: #fff; padding: 8px 16px; border-radius: 6px;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 50; font-size: 14px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); }
.actions.left { justify-content: flex-start; margin-top: 12px; }
.existing { margin-top: 16px; padding: 16px; border: 1px solid var(--warn-line); background: var(--warn-soft); border-radius: 6px; }
details.raw { margin-top: 4px; font-size: 13px; } details.raw summary { cursor: pointer; }
details.raw pre { margin: 8px 0; white-space: pre-wrap; font: 12px/1.5 ui-monospace, monospace; }
.imgwrap.wait { display: grid; place-items: center; min-height: 160px; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding-right: 8px; }
.drawer-head .close, .center-head .menu { display: none; }
@media (max-width: 1499px) {
  /* narrower than 1500px: the section/page list becomes a drawer so the two page panes keep ~450px each */
  .review-layout { grid-template-columns: minmax(0, 1fr) 304px; }
  .side { position: fixed; left: 0; top: 56px; bottom: 0; width: 280px; max-height: none; z-index: 30; border-radius: 0 var(--radius) var(--radius) 0;
    transform: translateX(-102%); transition: transform .18s; box-shadow: 4px 0 16px rgba(20, 30, 40, .18); }
  .side.open { transform: none; }
  .drawer-head .close, .center-head .menu { display: inline-flex; }
  .topbar-in { gap: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.fit { font-size: 13px; margin-top: 4px; padding: 0; min-height: 0; }
.fit.ok { color: var(--ok); } .fit.warn { color: var(--warn); font-weight: 600; } .fit.bad { color: var(--bad); font-weight: 600; }
.adj { display: flex; flex-direction: column; gap: 8px; }
.adj-row { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; font-size: 14px; }
.adj-row input[type=range] { width: 100%; accent-color: var(--accent); }
.ptrow { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; }
.ptrow.sub { flex-wrap: wrap; justify-content: space-between; }
.ptfield { display: flex; align-items: center; gap: 4px; }
.ptfield .ptin { width: 5.2em; text-align: center; font-variant-numeric: tabular-nums; padding: 4px 6px; font: inherit; }
.ptfield .ptin.bad { outline: 2px solid var(--bad); }
.qa-pending { margin-left: 8px; }
.adj-row output { min-width: 3.2em; text-align: right; font-variant-numeric: tabular-nums; }
.banner.warnlist { display: block; background: var(--warn-soft); color: var(--warn); margin-bottom: 8px; }
.banner.warnlist ul { margin: 4px 0 0; padding-left: 20px; font-size: 13px; }
