/* หน้าตาระบบสายส่ง — ออกแบบให้มือถือเป็นหลัก คนขับใช้กลางแดด ถือมือเดียว
   ปุ่มใหญ่ ตัวหนังสือใหญ่ คอนทราสต์สูง เพราะหน้าจอกลางแดดมองยาก */
:root {
  --bg: #f4f6f4; --card: #fff; --ink: #14251a; --dim: #5d6b61; --line: #dfe5e0;
  --brand: #14532d; --brand2: #1d7a44; --ok: #16794a; --warn: #b45309; --bad: #b91c1c;
  --r: 14px; --shadow: 0 1px 2px rgba(20,37,26,.06), 0 4px 16px rgba(20,37,26,.06);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* ต้องมาก่อนทุกกฎที่ตั้ง display — ไม่งั้น .modal{display:grid} จะทับ [hidden]
   แล้วแผ่นซ้อนจะค้างบังหน้าจอทั้งหน้าโดยไม่มีใครรู้ว่าทำไม (เจอจริงตอนทดสอบ 16/09/2026) */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink); font-size: 17px; line-height: 1.55;
  font-family: "Noto Sans Thai", "Sarabun", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
b { font-weight: 700; }
a { color: var(--brand2); }

header {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.mark {
  width: 36px; height: 36px; flex: none; border-radius: 10px; background: #fff2;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
}
.brand b { display: block; font-size: 16px; line-height: 1.2; }
.brand small { display: block; font-size: 12.5px; opacity: .85; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }

nav {
  position: sticky; top: 0; z-index: 20; display: flex; gap: 2px; overflow-x: auto;
  background: #fff; border-bottom: 1px solid var(--line); padding: 0 8px;
  scrollbar-width: none;
}
nav::-webkit-scrollbar { display: none; }
nav button {
  flex: none; border: 0; background: none; color: var(--dim); font: inherit; font-size: 15px;
  padding: 12px 12px 10px; border-bottom: 3px solid transparent; cursor: pointer;
}
nav button.on { color: var(--brand); font-weight: 700; border-bottom-color: var(--brand2); }

main { padding: 14px; max-width: 760px; margin: 0 auto; }
footer { padding: 18px 14px 28px; text-align: center; color: var(--dim); font-size: 12px; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 8px; }
h3 { font-size: 19px; margin: 0 0 4px; }
.sub { color: var(--dim); font-size: 14px; margin: 0 0 14px; }
.dim { color: var(--dim); }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.okt { color: var(--ok); font-weight: 700; }
.warnt { color: var(--warn); font-weight: 700; }
.badt { color: var(--bad); font-weight: 700; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font: inherit; font-weight: 600; padding: 12px 16px; border-radius: 12px; cursor: pointer;
  min-height: 48px;
}
.btn:active { transform: translateY(1px); }
.btn.p { background: var(--brand2); border-color: var(--brand2); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: #ffffff22; border-color: #ffffff44; color: #fff; }
.btn.sm { min-height: 38px; padding: 8px 12px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn.big { min-height: 64px; font-size: 19px; border-radius: 16px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

label { display: block; font-weight: 600; font-size: 15px; margin: 14px 0 6px; }
label:first-child { margin-top: 0; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 17px; padding: 12px; border: 1px solid var(--line);
  border-radius: 12px; background: #fff; color: var(--ink); min-height: 48px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand2); outline-offset: -1px; }
textarea { min-height: 84px; resize: vertical; }
.note { display: block; color: var(--dim); font-size: 13.5px; margin-top: 6px; font-weight: 400; }
.req { color: var(--bad); font-size: 12.5px; font-weight: 700; }

.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.mt { margin-top: 16px; } .mt-s { margin-top: 8px; } .mb { margin-bottom: 12px; }

.pill { display: inline-block; font-size: 12.5px; font-weight: 700; padding: 3px 9px;
  border-radius: 999px; background: #eef2ee; color: var(--dim); vertical-align: middle; }
.pill.ok { background: #dcfce7; color: #14532d; }
.pill.warn { background: #fef3c7; color: #78350f; }
.pill.bad { background: #fee2e2; color: #7f1d1d; }

.box { border-radius: 12px; padding: 12px 14px; margin: 10px 0; font-size: 15px; }
.ok-box { background: #ecfdf5; border: 1px solid #a7f3d0; }
/* ช่องมองภาพของกล้อง — ให้เต็มความกว้างและสูงพอเล็งได้จริงบนมือถือ
   พื้นดำเพราะระหว่างรอกล้องติดจะได้ไม่เห็นเป็นกล่องขาวว่าง ๆ แล้วนึกว่าค้าง */
.cam { background: #000; border-radius: var(--r); overflow: hidden; margin-bottom: 8px; }
.cam video { display: block; width: 100%; max-height: 52vh; object-fit: contain; }

/* ปุ่มกรองแบบแถบ — เรียงในแนวนอน เลื่อนได้ถ้ายาวเกินจอ
   ใช้ปุ่มแทน dropdown เพราะกดทีเดียวเห็นผลเลย ไม่ต้องเปิดเมนูก่อน */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.chip { background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 13px; font: inherit; font-size: 14.5px; color: var(--dim); cursor: pointer; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }

/* ปุ่มเลือกแบบการ์ด — ใช้ตอนเลือกประเภทคนขับ
   ทำเป็นปุ่มใหญ่แทน dropdown เพราะต้องอธิบายแต่ละแบบด้วย และกดง่ายกว่าบนมือถือ */
.pickers { display: grid; gap: 8px; margin-bottom: 4px; }
.pick { text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 11px 13px; font: inherit; color: inherit; cursor: pointer; }
.pick b { display: block; font-size: 15.5px; }
.pick span { display: block; color: var(--dim); font-size: 13.5px; margin-top: 2px; }
.pick.on { border-color: var(--brand2); box-shadow: inset 0 0 0 1px var(--brand2); background: #f0fdf4; }

.ok-box { background: #f0fdf4; border: 1px solid #bbf7d0; }
.warn-box { background: #fffbeb; border: 1px solid #fde68a; }
.bad-box { background: #fef2f2; border: 1px solid #fecaca; }

/* แถบเตือนว่าเครื่องนี้ยังใช้ตอนออฟไลน์ไม่ได้ — ตั้งใจให้เด่นและปิดไม่ได้
   เพราะถ้าพลาดข้อนี้ คนขับจะออกไปทั้งวันแล้วบันทึกอะไรไม่ได้เลย */
.warnbar { background: #fef2f2; border: 1px solid #fecaca; border-left: 5px solid var(--bad);
  border-radius: var(--r); padding: 12px 14px; margin-bottom: 12px; line-height: 1.6; }
.warnbar div { color: var(--dim); font-size: 14px; margin: 4px 0 8px; }
.warnbar a { font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat .k { font-size: 12.5px; color: var(--dim); }
.stat .v { font-size: 22px; font-weight: 700; line-height: 1.2; }
.stat .v small { font-size: 13px; font-weight: 600; color: var(--dim); }
.stat.hot { border-color: #fbbf24; background: #fffbeb; }

.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: block; width: 100%; text-align: left; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; font: inherit; color: inherit; cursor: pointer;
}
.item .t { font-weight: 700; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.item .s { color: var(--dim); font-size: 14px; margin-top: 3px; }

/* ไทม์ไลน์รอบส่ง — อ่านจากบนลงล่างตามเวลาจริง */
.tl { position: relative; padding-left: 26px; }
.tl::before { content: ''; position: absolute; left: 8px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl .node { position: relative; padding: 10px 0; }
.tl .node::before {
  content: ''; position: absolute; left: -22px; top: 16px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--brand2); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--line);
}
.tl .node.warn::before { background: var(--warn); }
.tl .node.end::before { background: var(--ok); }
.tl .when { font-size: 13px; color: var(--dim); }
.tl .what { font-weight: 700; }

.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.thumbs.big img { width: 120px; height: 120px; }
.th { position: relative; display: inline-block; }
.thx { position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%;
  border: 0; background: var(--bad); color: #fff; font-size: 13px; cursor: pointer; line-height: 1; }

.modal { position: fixed; inset: 0; z-index: 60; background: #0006; display: grid;
  place-items: end center; padding: 0; }
.sheet {
  background: #fff; width: 100%; max-width: 620px; max-height: 92vh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
@media (min-width: 720px) { .modal { place-items: center; } .sheet { border-radius: 18px; } }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 90;
  background: #14251aef; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 15px;
  max-width: 92vw; text-align: center; box-shadow: var(--shadow);
  /* ขึ้นบรรทัดใหม่ได้ — ข้อความบอกสาเหตุตอนต่อเซิร์ฟเวอร์ไม่ได้มีหลายบรรทัด */
  white-space: pre-line; line-height: 1.45; }
.toast.bad { background: #7f1d1def; }

/* white-space: pre-line — ป้ายนี้ต้องขึ้นบรรทัดใหม่ได้ เพราะตอนต่อไม่ได้จะติดสาเหตุ
   กับที่อยู่ที่ยิงไปหามาด้วย ถ้าไม่ใส่ ข้อความจะต่อกันเป็นพืดจนอ่านไม่รู้เรื่อง */
.net { position: sticky; top: 0; z-index: 40; padding: 8px 14px; font-size: 14px; font-weight: 600;
  text-align: center; background: #fef3c7; color: #78350f; border-bottom: 1px solid #fde68a;
  white-space: pre-line; line-height: 1.45; }
.net.bad { background: #fee2e2; color: #7f1d1d; border-bottom-color: #fecaca; }

.gps { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #fafbfa; }
.gps.good { border-color: #a7f3d0; background: #ecfdf5; }
.gps.rough { border-color: #fde68a; background: #fffbeb; }
.gps.none { border-color: #fecaca; background: #fef2f2; }

.empty { text-align: center; color: var(--dim); padding: 28px 12px; }
.tw { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--dim); font-size: 13px; font-weight: 600; }

@media (max-width: 560px) {
  table.stack thead { display: none; }
  table.stack tr { display: block; border: 1px solid var(--line); border-radius: 12px;
    margin-bottom: 8px; padding: 4px 2px; }
  table.stack td { display: flex; gap: 10px; border: 0; padding: 5px 10px; }
  table.stack td::before { content: attr(data-l); color: var(--dim); font-size: 13px;
    min-width: 88px; flex: none; }
}
