/* Termite One · แอปช่าง — ใช้กลางแดด มือเปื้อน: ตัวใหญ่ ปุ่มสูง ≥ 48px หนึ่งจอมีปุ่มหลักปุ่มเดียว
   สีชุดเดียวกับหน้า CREW บนกระดาน (CRW-05…08) · ธีมสว่างอย่างเดียวโดยตั้งใจ (อ่านกลางแดดง่ายกว่า)
   CSP ห้าม style="" ใน HTML — ค่าที่คำนวณได้ตั้งผ่านสคริปต์ */
:root {
  --ground: #F4F2EE;
  --paper: #FFFFFF;
  --line: #E3DED5;
  --line2: #CFC7BA;
  --ink: #17140F;
  --muted: #6A6257;
  --crew: #8A4210;
  --crew-bg: #FBEFE3;
  --go: #0F6B6B;
  --go-bg: #E3F2F1;
  --navy: #10263F;
  --warn: #8A5F00;
  --warn-bg: #FFF3CC;
  --warn-line: #E3C766;
  --bad: #A11F32;
  --bad-bg: #FCE9EC;
  --ai: #3D359B;
  --ai-bg: #EEECFB;
  --head: 'Anuphan', 'Leelawadee UI', Tahoma, sans-serif;
  --body: 'IBM Plex Sans Thai', 'Leelawadee UI', Tahoma, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ground); color: var(--ink); font-family: var(--body); font-size: 16px; line-height: 1.45; -webkit-tap-highlight-color: transparent; }
a { color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--crew); outline-offset: 2px; }

/* ── โครง ── */
.shell { min-height: 100vh; }
.view { max-width: 560px; margin: 0 auto; padding: 12px 14px calc(96px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.mockbar { position: sticky; top: 0; z-index: 12; background: var(--navy); color: #fff; font-size: 12.5px; text-align: center; padding: calc(4px + env(safe-area-inset-top)) 10px 4px; }
.pending { position: sticky; top: 0; z-index: 11; background: var(--warn-bg); color: var(--warn); border-bottom: 2px solid var(--warn-line);
           font-size: 14px; font-weight: 700; padding: 8px 14px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.mockbar:not([hidden]) + .pending { top: 26px; }
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr);
       background: var(--paper); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.nav a { text-align: center; text-decoration: none; color: var(--muted); font-size: 14px; font-weight: 600; padding: 14px 0 16px; min-height: 56px; position: relative; }
.nav a.on { color: var(--crew); box-shadow: inset 0 3px 0 var(--crew); }
.nav a .badge { position: absolute; top: 8px; margin-left: 4px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; padding: 0 5px; }

/* ── หัวจอ ── */
.top { display: flex; align-items: center; gap: 10px; padding-top: 4px; }
.top .t { flex: 1; min-width: 0; }
.top h1 { font-family: var(--head); font-size: 22px; line-height: 1.15; margin: 0; }
.top small { display: block; color: var(--muted); font-size: 13px; }
.back { text-decoration: none; font-size: 26px; line-height: 1; width: 36px; height: 44px; display: grid; place-items: center; }
.me { width: 44px; height: 44px; border-radius: 50%; background: var(--crew); color: #fff; display: grid; place-items: center; font-weight: 700; text-decoration: none; flex-shrink: 0; }
h2 { font-family: var(--head); font-size: 17px; margin: 6px 0 0; }

/* ── การ์ด ── */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.card.hot { border: 2px solid var(--crew); background: var(--crew-bg); }
.card.warn { background: var(--warn-bg); border-color: var(--warn-line); }
.card.bad { background: var(--bad-bg); border-color: #E7B8C0; }
.card.go { background: var(--go-bg); border-color: #BFE1DE; }
.card.ai { background: var(--ai-bg); border-color: #D5D1F3; }
.card.link { text-decoration: none; color: inherit; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.row.top-a { align-items: flex-start; }
.k { font-size: 13px; color: var(--muted); }
.big { font-family: var(--head); font-weight: 700; font-size: 18px; line-height: 1.25; }
.num { font-variant-numeric: tabular-nums; font-family: var(--head); font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.pill { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 99px; white-space: nowrap; }
.p-go { background: var(--go); color: #fff; }
.p-crew { background: var(--crew); color: #fff; }
.p-warn { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn-line); }
.p-mut { background: #ECE8E1; color: var(--muted); }
.p-bad { background: var(--bad-bg); color: var(--bad); }
.p-ai { background: var(--ai); color: #fff; }

/* ── ปุ่ม ── */
.btn { display: block; width: 100%; border: 0; border-radius: 14px; padding: 14px 12px; min-height: 52px; text-align: center; text-decoration: none;
       font-family: var(--head); font-weight: 700; font-size: 17px; cursor: pointer; }
.btn.pri { background: var(--go); color: #fff; }
.btn.dark { background: var(--navy); color: #fff; }
.btn.line { background: var(--paper); border: 1.5px solid var(--line2); color: var(--ink); }
.btn.danger { background: var(--paper); border: 1.5px solid #E7B8C0; color: var(--bad); }
.btn.sm { min-height: 44px; padding: 10px; font-size: 15px; border-radius: 12px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btns { display: flex; gap: 8px; }
.btns > * { flex: 1; }
.stick { position: sticky; bottom: calc(66px + env(safe-area-inset-bottom)); z-index: 5; display: flex; flex-direction: column; gap: 8px; padding-top: 6px;
         background: linear-gradient(to bottom, transparent, var(--ground) 30%); }
.stick .note { font-size: 12.5px; color: var(--muted); text-align: center; }

/* ── รายการ/ตัวเลข ── */
.lines { display: flex; flex-direction: column; gap: 4px; font-size: 14.5px; }
.lines .row b { font-variant-numeric: tabular-nums; }
.lines .tot { border-top: 1.5px solid var(--ink); padding-top: 6px; margin-top: 2px; font-size: 16px; }
.track { display: flex; flex-direction: column; }
.tk { display: flex; gap: 10px; align-items: flex-start; position: relative; padding-bottom: 10px; }
.tk::before { content: ""; position: absolute; left: 9px; top: 20px; bottom: 0; border-left: 2px solid var(--line); }
.tk:last-child::before { display: none; }
.tk .o { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line2); background: var(--paper); flex-shrink: 0; z-index: 1; }
.tk.d .o { background: var(--go); border-color: var(--go); }
.tk.c .o { border-color: var(--crew); box-shadow: 0 0 0 4px var(--crew-bg); }
.tk.x .o { border-color: var(--bad); background: var(--bad-bg); }
.tk b { display: block; font-size: 14.5px; }
.tk span { font-size: 12.5px; color: var(--muted); }

/* ── หลักฐานตามหัวข้อ ── */
.progress { height: 8px; background: #E6E0D6; border-radius: 4px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--go); width: 0; }
.topic { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: flex; gap: 10px; align-items: flex-start; }
.topic.now { border: 2px solid var(--crew); }
.topic.lock { opacity: .5; }
.topic .code { font-family: var(--head); font-weight: 700; min-width: 40px; font-size: 15px; }
.topic .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.topic .st { font-size: 13px; font-weight: 700; }
.st.ok { color: var(--go); } .st.skip { color: var(--warn); } .st.no { color: var(--muted); } .st.req { color: var(--bad); }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; border: 2px solid var(--line); }
.thumbs img.local { border-color: var(--warn-line); }
.chipbtns { display: flex; gap: 6px; flex-wrap: wrap; }
.chipbtn { border: 1.5px solid var(--line2); background: var(--paper); border-radius: 10px; padding: 8px 12px; min-height: 40px; font-size: 14px; font-weight: 600; cursor: pointer; }
.chipbtn.on { border-color: var(--crew); background: var(--crew-bg); color: var(--crew); }

/* ── ฟอร์ม ── */
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 600; }
label.f small { font-weight: 400; color: var(--muted); }
input.in, select.in, textarea.in { width: 100%; border: 1.5px solid var(--line2); border-radius: 12px; padding: 12px; min-height: 48px; background: var(--paper); font-size: 16px; }
textarea.in { min-height: 88px; resize: vertical; }
input.in.ok { border-color: var(--go); } input.in.badv { border-color: var(--bad); }
.hint { font-size: 12.5px; } .hint.ok { color: var(--go); } .hint.bad { color: var(--bad); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; padding: 6px 0; }
.check input { width: 24px; height: 24px; flex-shrink: 0; margin-top: 1px; accent-color: var(--go); }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button { width: 44px; height: 44px; border-radius: 12px; border: 1.5px solid var(--line2); background: var(--paper); font-size: 22px; font-weight: 700; cursor: pointer; }
.qty b { min-width: 44px; text-align: center; font-size: 18px; font-variant-numeric: tabular-nums; }

/* ── ลายเซ็น ── */
.sigwrap { position: relative; background: var(--paper); border: 2px dashed var(--line2); border-radius: 14px; height: 180px; touch-action: none; }
.sigwrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 14px; }
.sigwrap .ln { position: absolute; left: 18px; right: 18px; bottom: 36px; border-top: 1px dashed var(--line2); pointer-events: none; }
.sigwrap .ph { position: absolute; left: 0; right: 0; bottom: 10px; text-align: center; font-size: 12.5px; color: var(--muted); pointer-events: none; }

/* ── ปฏิทิน ── */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; text-align: center; }
.cal .h { font-size: 12px; color: var(--muted); font-weight: 700; padding: 2px 0; }
.cal button.d { height: 50px; border-radius: 11px; background: var(--paper); border: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center;
                font-weight: 700; font-variant-numeric: tabular-nums; cursor: pointer; padding: 0; line-height: 1.05; }
.cal button.d i { font-style: normal; font-size: 9.5px; font-weight: 700; margin-top: 3px; }
.cal button.d.off { background: repeating-linear-gradient(135deg, var(--bad-bg) 0 6px, #fff 6px 11px); border-color: #E7B8C0; color: var(--bad); }
.cal button.d.am, .cal button.d.pm { border-color: #E7B8C0; color: var(--bad); }
.cal button.d.am { background: linear-gradient(to bottom, var(--bad-bg) 50%, #fff 50%); }
.cal button.d.pm { background: linear-gradient(to top, var(--bad-bg) 50%, #fff 50%); }
.cal button.d.job { background: var(--navy); color: #fff; border-color: var(--navy); cursor: not-allowed; }
.cal button.d.past { opacity: .35; cursor: not-allowed; }
.cal button.d.today { outline: 2.5px solid var(--crew); outline-offset: 1px; }
.cal .blank { height: 50px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--muted); }

/* ── แชทงาน ── */
.chat { display: flex; flex-direction: column; gap: 6px; }
.bub { max-width: 82%; padding: 8px 12px; border-radius: 14px; font-size: 14.5px; }
.bub.out { align-self: flex-end; background: var(--go-bg); }
.bub.in { align-self: flex-start; background: var(--paper); border: 1px solid var(--line); }
.bub small { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ── แผ่นล่าง (sheet) ── */
.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(23, 20, 15, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet .panel { background: var(--ground); width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; border-radius: 20px 20px 0 0;
                padding: 16px 14px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.sheet .panel h3 { font-family: var(--head); font-size: 19px; margin: 0; }

/* ── เครื่องมือจำลอง ── */
.dev { border: 2px dashed var(--navy); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; background: #EEF2F7; }
.dev b { font-size: 13px; color: var(--navy); }
.toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40; background: var(--ink); color: #fff;
         padding: 10px 16px; border-radius: 12px; font-size: 14.5px; max-width: 92vw; box-shadow: 0 8px 24px rgba(0,0,0,.25); }

@media (prefers-reduced-motion: no-preference) { .sheet .panel { animation: up .18s ease-out; } @keyframes up { from { transform: translateY(24px); opacity: .6; } } }
