:root {
  --bg: #f6f5f1; --card: #ffffff; --ink: #1b1b1a; --ink2: #52514e; --muted: #898781;
  --line: #e4e2db; --accent: #2a78d6; --accent-ink: #1c5cab; --ok: #0a7d32; --bad: #c43030;
  --warn-bg: #fff4d6; --warn-line: #e8c766; --warn-ink: #6b4e00;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Noto Sans", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 15px; line-height: 1.45; }
button, input, select { font: inherit; }
a { color: var(--accent-ink); }
[hidden] { display: none !important; }

/* ---------- app shell ---------- */
.top { position: sticky; top: 0; z-index: 5; background: #1b1b1a; color: #fff; }
.top .in { max-width: 980px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: .01em; margin-right: auto; }
.nav a { color: #d9d8d2; text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.nav a.on, .nav a:hover { background: #33322f; color: #fff; }
.top select, .top button { background: #33322f; color: #fff; border: 0; border-radius: 8px; padding: 6px 10px; cursor: pointer; }
main { max-width: 980px; margin: 0 auto; padding: 18px 16px 60px; }
h1 { font-size: 22px; margin: 6px 0 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 10px;
  padding: 11px 16px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: #ecebe6; color: var(--ink); }
.btn.dark { background: var(--ink); }
.btn.big { width: 100%; padding: 14px; font-size: 16px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); font-size: 13px; }
.err { color: var(--bad); }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--ink2); margin-bottom: 4px; }
.field input { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

/* login */
.login { max-width: 360px; margin: 10vh auto 0; }

/* upload */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin: 12px 0; }
.thumb { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: #fff; aspect-ratio: 3/4; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .n { position: absolute; left: 6px; top: 6px; background: #1b1b1acc; color: #fff; font-size: 12px; border-radius: 6px; padding: 1px 6px; }
.thumb .x { position: absolute; right: 6px; top: 6px; background: #fff; border: 0; border-radius: 50%; width: 26px; height: 26px; cursor: pointer; font-weight: 700; }
.quality { display: grid; gap: 8px; margin: 10px 0 16px; }
.quality label { display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; background: #fff; }
.quality label.on { border-color: var(--accent); background: #eef4fc; }
.quality small { color: var(--muted); }
.progress { margin-top: 12px; }
.bar { height: 8px; background: #ecebe6; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 30%; background: var(--accent); border-radius: 99px; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -30%; } 100% { margin-left: 100%; } }

/* doc page */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 7px 14px; cursor: pointer; }
.tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0 14px; }
.check { border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: 14px; }
.check.ok { background: #e9f6ee; border: 1px solid #b9e1c6; }
.check.bad { background: #fdecec; border: 1px solid #f1bcbc; }
.check ul { margin: 6px 0 0; padding-left: 18px; }
.photos { display: flex; gap: 8px; flex-wrap: wrap; }
.photos img { height: 120px; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; }

/* history / admin tables */
.tbl { width: 100%; border-collapse: collapse; background: #fff; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 10px; border-bottom: 1px solid #efeee9; vertical-align: top; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #faf9f6; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: #ecebe6; color: var(--ink2); margin-left: 4px; }
.pill.th { background: #eef4fc; color: var(--accent-ink); }
.pill.err { background: #fdecec; color: var(--bad); }
.scroll { overflow-x: auto; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.tile .k { font-size: 12px; color: var(--muted); }
.tile .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .s { font-size: 12px; color: var(--ink2); }
.settings { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 700px) { .settings { grid-template-columns: 2fr 1fr 1fr; } }
@media (max-width: 520px) { .top .in { gap: 8px; } .nav a { padding: 6px 8px; } }

/* ---------- translated document (screen + PDF) ---------- */
.doc { background: #fff; color: #1b1b1a; padding: 26px 28px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; line-height: 1.5; }
.doc.th { font-family: "Noto Sans Thai", "Noto Sans", sans-serif; }
.doc .banner { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink); padding: 6px 10px; border-radius: 6px; font-size: 11.5px; margin-bottom: 12px; }
.doc .head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; border-bottom: 2px solid #1b1b1a; padding-bottom: 6px; margin-bottom: 12px; }
.doc .head h2 { font-size: 22px; margin: 0; line-height: 1.2; }
.doc .head .meta { text-align: right; color: #52514e; font-size: 11.5px; white-space: nowrap; }
.doc h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: #2a5fa8; margin: 16px 0 6px; }
.doc .short { background: #eef4fc; border-left: 4px solid #2a78d6; padding: 8px 12px; border-radius: 4px; }
.doc .short ul { margin: 4px 0 0; padding-left: 18px; }
.doc .fmt { font-size: 11.5px; color: #52514e; margin-top: 6px; }
.doc table { width: 100%; border-collapse: collapse; }
.doc .kv td { padding: 4px 8px; border-bottom: 1px solid #ebe9e3; vertical-align: top; }
.doc .kv td:first-child { color: #52514e; width: 36%; }
.doc .kv td:last-child { font-weight: 600; word-break: break-word; }
.doc .parties { display: flex; gap: 10px; flex-wrap: wrap; }
.doc .party { flex: 1 1 220px; border: 1px solid #dcdad3; border-radius: 6px; padding: 8px 10px; }
.doc .party .r { font-size: 11px; color: #898781; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.doc .party .l0 { font-weight: 700; }
.doc .items th { background: #1b1b1a; color: #fff; font-size: 11px; text-align: left; padding: 5px 6px; }
.doc .items td { padding: 6px; border-bottom: 1px solid #ebe9e3; vertical-align: top; }
.doc .items tbody:nth-of-type(even) td { background: #faf9f6; }
.doc .items .note { font-size: 11px; color: #6b6a65; margin-top: 2px; }
.doc .items td.n { text-align: right; white-space: nowrap; }
.doc .totals { width: 60%; margin-left: auto; }
.doc .totals td { padding: 4px 8px; }
.doc .totals td:last-child { text-align: right; white-space: nowrap; font-weight: 600; }
.doc .due { margin-top: 6px; display: flex; justify-content: space-between; align-items: center; gap: 10px; background: #1b1b1a; color: #fff; border-radius: 6px; padding: 8px 12px; font-size: 14px; }
.doc .due b { font-size: 17px; white-space: nowrap; }
.doc .text p { margin: 4px 0; }
.doc .notes { font-size: 11.5px; color: #6b4e00; background: var(--warn-bg); border-radius: 6px; padding: 6px 10px; margin-top: 12px; }
.doc .foot { margin-top: 16px; border-top: 1px solid #dcdad3; padding-top: 6px; font-size: 11px; color: #6b6a65; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.doc .avoid, .doc tr { break-inside: avoid; page-break-inside: avoid; }
@media (max-width: 600px) {
  .doc { padding: 16px 14px; }
  .doc .totals { width: 100%; }
  .doc .items { font-size: 12px; }
}
