/* ระบบติดตามงานพัสดุ รพ.ตาพระยา
   สีทั้งหมดมาจาก design handoff — ห้ามเปลี่ยนความหมายของสี
   ขนาดตัวอักษรขยายจาก mockup ตาม UX.md (เนื้อตาราง 13.5px แทน 12px) */

:root {
  --green-dark: #0f3d33;
  /* โทนเขียวอมฟ้าปลายไล่สี ให้เข้ากับโลโก้ — ใช้กับ chrome ของเว็บเท่านั้น
     ห้ามนำไปใช้แทนสีสถานะ เพราะความหมายของสีต้องคงที่ทั้งเว็บ */
  --brand-deep: #0c4a58;
  --green-logo: #1b6f5c;
  --green: #0f6f5c;
  --green-ok: #2f8a4c;
  --green-ok-bg: #e2f2e7;
  --green-ok-text: #256e3c;
  --yellow: #d99a1f;
  --yellow-bg: #f6e8c8;
  --yellow-text: #8a6410;
  --yellow-halo: #f6e8c8;
  --red: #c8452c;
  --red-bg: #fbe9e5;
  --red-row: #fdf5f3;
  --red-text: #a2442f;
  --red-halo: #f5d9d3;
  --blue: #2a5ca8;
  --blue-bg: #eef4ff;

  --ink: #17322b;
  --ink-2: #243530;
  --muted: #5a6a64;
  --muted-2: #6b7a75;
  --faint: #8a968f;
  --line: #e3e8e6;
  --line-soft: #eef1f0;
  --dot-empty: #e4e9e6;
  --dot-line: #c9d4cf;
  --page: #f4f6f5;
  --page-2: #f6f8f7;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: "Noto Sans Thai", system-ui, -apple-system, sans-serif;
  font-size: 13.5px;
  line-height: 1.55;
}

a { color: var(--green); text-decoration: none; }

/* ---------------------------------------------------------------- header */
.hdr {
  background: linear-gradient(105deg, var(--green-dark) 0%, var(--brand-deep) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  flex-wrap: wrap;
}
.hdr .logo {
  width: 34px; height: 34px;
  border-radius: 9px;
  flex: none;
  display: block;
}
.hdr .title { font-weight: 600; font-size: 15px; }
.hdr .sub { font-size: 11.5px; opacity: .65; }
.nav { display: flex; gap: 2px; margin-left: 20px; font-size: 13px; flex-wrap: wrap; }
.nav a { padding: 7px 14px; border-radius: 7px; opacity: .72; color: #fff; }
.nav a.on { background: rgba(255, 255, 255, .14); font-weight: 600; opacity: 1; }
.nav a.off { opacity: .4; cursor: not-allowed; }
.hdr .me { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 12.5px; opacity: .85; }

.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px; color: #fff;
}

/* ---------------------------------------------------------------- KPI */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  padding: 14px 20px;
  background: var(--page-2);
  border-bottom: 1px solid var(--line);
}
.kpi {
  background: #fff; border: 1px solid var(--line);
  border-radius: 9px; padding: 10px 14px;
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.kpi .label { font-size: 12px; color: var(--muted-2); }
.kpi .num { font-size: 24px; font-weight: 700; color: var(--ink); }
.kpi .hint { font-size: 11.5px; color: var(--faint); }
.kpi.ok .num { color: var(--green-ok); }
.kpi.warn .num { color: var(--yellow); }
.kpi.late { border-color: #f0d5cd; box-shadow: inset 3px 0 0 var(--red); }
.kpi.late .label { color: var(--red-text); }
.kpi.late .num { color: var(--red); }
.kpi.unknown { border-style: dashed; }
.kpi.unknown .num { color: var(--muted); }
.kpi.on { outline: 2px solid var(--green); outline-offset: -2px; }

/* ---------------------------------------------------------------- toolbar */
.tools {
  display: flex; gap: 8px; align-items: center;
  padding: 12px 20px; flex-wrap: wrap;
}
.tools input[type="search"],
.tools select {
  font: inherit; font-size: 13px;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; color: #3c4a45; background: #fff;
}
.tools input[type="search"] { flex: 1; min-width: 200px; background: #f2f5f4; }
.toggle {
  font-size: 13px; padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; color: #3c4a45;
  cursor: pointer; font-family: inherit;
}
.toggle.late-on { border-color: var(--red); color: var(--red); font-weight: 600; }
.toggle.unk-on { border-color: var(--muted); color: var(--muted); font-weight: 600; border-style: dashed; }
.toggle[aria-pressed="true"] { background: var(--red-bg); }
.toggle.unk-on[aria-pressed="true"] { background: var(--page-2); }
.btn-primary {
  margin-left: auto; font-size: 13px; padding: 8px 16px;
  border-radius: 8px; background: var(--green); color: #fff;
  font-weight: 600; border: 0; cursor: pointer; font-family: inherit;
}
.btn-primary[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------------------------------------------------------------- table */
.wrap { padding: 0 20px 20px; }
.tbl-scroll { overflow-x: auto; }
.row {
  display: grid;
  grid-template-columns: 92px 104px 1.1fr 1.7fr 96px 104px 248px 116px 104px;
  align-items: center;
  gap: 18px;
  padding: 10px;
  border-bottom: 1px solid var(--line-soft);
  min-width: 1300px;
}
.row.head {
  font-size: 12px; color: var(--muted-2); font-weight: 600;
  border-bottom: 2px solid #dfe5e2;
  position: sticky; top: 0; background: var(--page); z-index: 1;
}
.row.item { font-size: 13.5px; color: var(--ink-2); cursor: pointer; }
.row.item:hover { background: var(--page-2); }
.row.is-late { background: var(--red-row); }
.row.is-late:hover { background: #fbeeea; }
.row.is-unknown { background: repeating-linear-gradient(45deg, #fafbfa, #fafbfa 8px, #f4f6f5 8px, #f4f6f5 16px); }
.num-cell { text-align: right; font-weight: 600; }
.po-no { font-weight: 600; }
.desc { color: #4a5a54; }
.desc .vendor { color: var(--faint); }
.chip {
  border-radius: 20px; padding: 2px 9px; font-size: 12px;
  display: inline-block; white-space: nowrap;
}
.chip.none { background: #f0f2f1; color: var(--faint); }

/* stepper 6 ขั้น */
.stepper { display: flex; align-items: center; gap: 3px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--dot-empty); flex: none; }
.dot.done { background: var(--green-ok); }
.dot.green { background: var(--green-ok); }
.dot.yellow { background: var(--yellow); box-shadow: 0 0 0 3px var(--yellow-halo); }
.dot.red { background: var(--red); box-shadow: 0 0 0 3px var(--red-halo); }
.dot.unknown { background: #fff; border: 2px dashed var(--faint); width: 12px; height: 12px; }
.bar { width: 14px; height: 2px; background: var(--dot-empty); flex: none; }
.bar.done { background: var(--dot-line); }
.step-name { margin-left: 6px; font-size: 11.5px; color: var(--muted-2); white-space: nowrap; }
.step-name.fin { color: var(--green-ok); font-weight: 600; }

/* badge วันค้าง */
.badge {
  border-radius: 6px; padding: 3px 9px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
  display: inline-block;
}
.badge.red { background: var(--red); color: #fff; }
.badge.yellow { background: var(--yellow-bg); color: var(--yellow-text); }
.badge.green { background: var(--green-ok-bg); color: var(--green-ok-text); }
.badge.done { background: var(--green-ok-bg); color: var(--green-ok-text); }
.badge.unknown { background: #eef1f0; color: var(--muted); font-weight: 600; }
.badge.cancelled { background: #eceeed; color: var(--faint); }
/* รอเอกสารครบ — ต้องอ่านออกว่า "ยังไม่เริ่มนับ" ไม่ใช่ "ปกติดี" และต้องไม่ใช่สีแดง
   เพราะช่วงที่รอเอกสารไม่ใช่ความช้าของเจ้าหน้าที่ (PROCESS.md ข้อ 1.2) */
.badge.waiting-docs { background: var(--blue-bg, #e8eff5); color: var(--blue, #2c5c85); font-weight: 600; }
.row.item.is-waiting-docs { background: repeating-linear-gradient(
    -45deg, transparent, transparent 7px, rgba(44,92,133,.045) 7px, rgba(44,92,133,.045) 14px); }
.warn-text { color: var(--yellow-text, #8a6100); font-weight: 600; }
.m-card.waiting_docs { border-left-color: var(--blue, #2c5c85); }
.m-badge.waiting-docs { background: var(--blue-bg, #e8eff5); color: var(--blue, #2c5c85); }

.act { text-align: right; }
.btn-nudge {
  border: 1px solid var(--red); color: var(--red); background: #fff;
  border-radius: 7px; padding: 5px 11px; font-size: 12px; font-weight: 600;
  font-family: inherit; cursor: pointer;
}
.act .note { color: var(--faint); font-size: 12px; }

.pager {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 10px 0; font-size: 12.5px; color: var(--faint); gap: 10px; flex-wrap: wrap;
}
.pager button {
  border: 1px solid var(--line); background: #fff; border-radius: 6px;
  padding: 4px 11px; font: inherit; font-size: 12.5px; cursor: pointer; color: var(--ink-2);
}
.pager button[disabled] { opacity: .4; cursor: not-allowed; }
.pager .cur { border-color: var(--green); color: var(--green); font-weight: 600; }

.empty { padding: 40px 10px; text-align: center; color: var(--faint); }

/* แถบเตือนคุณภาพข้อมูล */
.notice {
  margin: 0 20px 14px; padding: 10px 14px;
  background: #fffdf3; border: 1px solid #f0e4c0; border-radius: 9px;
  font-size: 12.5px; color: #6b5a20; line-height: 1.65;
}
.notice b { color: #4d4116; }

/* ---------------------------------------------------------------- detail */
.crumb { font-size: 13px; opacity: .8; }
.crumb b { opacity: 1; }
.detail { display: grid; grid-template-columns: 1.05fr .95fr; gap: 14px; padding: 16px 20px; }
@media (max-width: 900px) { .detail { grid-template-columns: 1fr; } }
.col { display: flex; flex-direction: column; gap: 12px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.card h3 { font-size: 14px; font-weight: 700; color: var(--ink); margin: 0 0 12px; }
.card .head-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.po-title { font-size: 17px; font-weight: 700; color: var(--ink); }
.po-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.facts { display: flex; gap: 18px; margin-top: 12px; font-size: 12.5px; color: #3c4a45; flex-wrap: wrap; }
.facts .k { color: var(--faint); font-size: 11.5px; }
.facts b { font-size: 15px; }

/* timeline แนวตั้ง */
.tl { display: flex; flex-direction: column; font-size: 12.5px; }
.tl-row { display: grid; grid-template-columns: 20px 1fr auto; gap: 10px; }
.tl-rail { display: flex; flex-direction: column; align-items: center; }
.tl-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--dot-empty); display: grid; place-items: center;
  font-size: 9px; color: #fff; flex: none;
}
.tl-dot.done { background: var(--green-ok); }
.tl-dot.green { background: var(--green-ok); }
.tl-dot.yellow { background: var(--yellow); box-shadow: 0 0 0 3px var(--yellow-halo); }
.tl-dot.red { background: var(--red); box-shadow: 0 0 0 3px var(--red-halo); }
.tl-dot.unknown { background: #fff; border: 2px dashed var(--faint); }
.tl-line { width: 2px; flex: 1; background: var(--dot-empty); min-height: 14px; }
.tl-line.done { background: var(--dot-line); }
.tl-body { padding-bottom: 16px; }
.tl-body b { color: var(--ink); }
.tl-body.now b { color: var(--red); }
.tl-body .meta { color: var(--muted-2); }
.tl-body.future { color: var(--faint); }
.tl-date { color: var(--faint); white-space: nowrap; }
.tl-date.now { color: var(--red); font-weight: 700; }

.list-line {
  display: grid; grid-template-columns: auto 1fr auto; gap: 8px;
  border-bottom: 1px solid var(--line-soft); padding: 7px 0; font-size: 12.5px;
}
.list-line:last-child { border-bottom: 0; }
.list-line b { color: var(--green); }
.list-line .when { color: var(--faint); }

.comment { background: var(--page-2); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; margin-bottom: 8px; }
.comment .when { color: var(--faint); font-size: 11.5px; }

.issue {
  border-left: 3px solid var(--yellow); background: #fffdf3;
  padding: 7px 10px; font-size: 12px; border-radius: 0 6px 6px 0; margin-bottom: 7px;
  color: #6b5a20;
}
.issue.error { border-left-color: var(--red); background: var(--red-bg); color: var(--red-text); }
.issue .kind { font-weight: 700; }

.muted-note { color: var(--faint); font-size: 12.5px; }
.back { color: #fff; opacity: .85; font-size: 13px; }

.pill-todo {
  border: 1px dashed var(--line); color: var(--faint);
  border-radius: 8px; padding: 7px 14px; font-size: 12.5px; display: inline-block;
}

/* ================================================================ เฟส 4: ฟอร์ม */

.me {
  margin-left: auto; display: flex; align-items: center; gap: 10px;
  font-size: 12.5px; background: rgba(255,255,255,.08); color: #fff;
  border: 1px solid rgba(255,255,255,.18); border-radius: 22px;
  padding: 4px 6px 4px 14px; cursor: pointer; font-family: inherit;
}
.me:hover { background: rgba(255,255,255,.16); }
.me .need-pick { color: #f6e8c8; font-weight: 600; }

.modal-bg {
  position: fixed; inset: 0; background: rgba(15,40,34,.45);
  display: grid; place-items: center; padding: 20px; z-index: 50;
  overflow-y: auto;
}
.modal {
  background: #fff; border-radius: 12px; width: min(860px, 100%);
  max-height: 90vh; overflow-y: auto; box-shadow: 0 12px 40px rgba(0,0,0,.22);
}
.modal.narrow { width: min(460px, 100%); }
.modal-hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line-soft);
  position: sticky; top: 0; background: #fff; border-radius: 12px 12px 0 0;
}
.modal-hd h2 { margin: 0; font-size: 16px; color: var(--ink); }
.modal-hd .x {
  border: 0; background: none; font-size: 16px; color: var(--faint);
  cursor: pointer; padding: 4px 8px; font-family: inherit;
}
.modal form { padding: 18px 20px 0; }
.modal-note {
  margin: 0; padding: 12px 20px; font-size: 12.5px; color: var(--muted);
  line-height: 1.7;
}
.modal-note.warn {
  background: #fffdf3; border-bottom: 1px solid #f0e4c0; color: #6b5a20;
}
.modal-ft {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 16px 0 20px; position: sticky; bottom: 0; background: #fff;
}

.f-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .f-grid { grid-template-columns: 1fr; } }
/* attribute hidden ต้องชนะ display ของคลาสเสมอ — ไม่งั้น .f{display:flex}
   จะทำให้ช่องที่ JS สั่งซ่อน (เช่น หน่วยงานของบทบาทที่ไม่ต้องเลือก) โชว์ค้าง */
[hidden] { display: none !important; }

.f { display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.f.wide { grid-column: 1 / -1; }
.f > span { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.f .req { color: var(--red); }
.f input, .f select, .f textarea {
  font: inherit; font-size: 14px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 8px; color: var(--ink);
  background: #fff; width: 100%;
}
.f input:focus, .f select:focus, .f textarea:focus {
  outline: 2px solid var(--green); outline-offset: -1px; border-color: var(--green);
}
.f small { color: var(--faint); font-size: 11.5px; }

.f-err {
  margin-top: 14px; background: var(--red-bg); color: var(--red-text);
  border: 1px solid #f0d5cd; border-radius: 8px; padding: 10px 12px; font-size: 13px;
}

.btn-primary-solid {
  background: var(--green); color: #fff; border: 0; border-radius: 8px;
  padding: 10px 20px; font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.btn-ghost {
  background: #fff; color: #3c4a45; border: 1px solid #cfd8d4; border-radius: 8px;
  padding: 10px 18px; font: inherit; font-size: 13.5px; cursor: pointer;
}
.btn-danger {
  background: var(--red); color: #fff; border: 0; border-radius: 8px;
  padding: 10px 20px; font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.btn-link {
  color: var(--green); font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }

/* ปุ่มยืนยันขั้นตอนบน timeline */
.step-actions { display: flex; gap: 7px; margin-top: 8px; flex-wrap: wrap; }
.btn-step {
  background: var(--green); color: #fff; border: 0; border-radius: 8px;
  padding: 9px 16px; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  min-height: 40px;
}
.btn-step:disabled { opacity: .5; cursor: wait; }
.step-actions .btn-ghost { padding: 9px 14px; font-size: 12.5px; min-height: 40px; }

/* ช่องพิมพ์บันทึก */
.cmt-form { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.cmt-form textarea {
  font: inherit; font-size: 13px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 8px; resize: vertical;
}
.cmt-blocker { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.cmt-form button { align-self: flex-end; }

/* เลือกว่าเราคือใคร */
.user-list { display: flex; flex-direction: column; gap: 8px; padding: 16px 20px 20px; }
.user-pick {
  display: flex; align-items: center; gap: 12px; text-align: left;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  background: #fff; cursor: pointer; font: inherit; min-height: 52px;
}
.user-pick:hover { background: var(--page-2); }
.user-pick.on { border-color: var(--green); background: #f1f7f5; }
.user-pick b { display: block; font-size: 14px; color: var(--ink); }
.user-pick small { color: var(--faint); font-size: 12px; }

/* แจ้งผลการบันทึก */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 22px;
  font-size: 13.5px; z-index: 100; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast.bad { background: var(--red); }

/* ================================================================ เฟส 5: เข้าสู่ระบบ */

.login-page {
  min-height: 100vh; display: grid; place-items: center;
  padding: 24px;
  background: linear-gradient(140deg, #12513f 0%, var(--green-dark) 45%, var(--brand-deep) 100%);
}
.login-card {
  background: #fff; border-radius: 14px; padding: 32px 30px 26px;
  width: min(400px, 100%); box-shadow: 0 14px 44px rgba(0,0,0,.28);
  display: flex; flex-direction: column; gap: 14px;
}
.login-logo {
  width: 64px; height: 64px; border-radius: 16px;
  align-self: center; display: block;
}
.login-card h1 {
  font-size: 19px; margin: 0; text-align: center; color: var(--ink);
}
.login-sub {
  margin: -10px 0 6px; text-align: center; color: var(--faint); font-size: 13px;
}
.login-btn { min-height: 46px; font-size: 15px; }
.login-help {
  margin: 4px 0 0; text-align: center; color: var(--faint); font-size: 12px; line-height: 1.6;
}

/* เมนูผู้ใช้มุมขวาบน */
.me-box { margin-left: auto; position: relative; }
.me-box .me { margin-left: 0; }
.me-menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.16); overflow: hidden; min-width: 170px; z-index: 40;
}
.me-menu button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 11px 16px; font: inherit; font-size: 13.5px; color: var(--ink-2); cursor: pointer;
}
.me-menu button:hover { background: var(--page-2); }

/* ================================================================ หน้ามือถือ 1d */

.m-wrap { padding-bottom: 76px; }

.m-hd { background: linear-gradient(140deg, var(--green-dark) 0%, var(--brand-deep) 100%); color: #fff; padding: 14px 16px 14px; }
.m-greet { display: flex; align-items: center; gap: 11px; }
.m-hello { font-weight: 600; font-size: 16px; }
.m-date { font-size: 12px; opacity: .72; }
.m-stats { display: flex; gap: 8px; margin-top: 13px; }
.m-stat {
  flex: 1; background: rgba(255,255,255,.1); border-radius: 9px;
  padding: 9px 8px; text-align: center;
}
.m-stat b { display: block; font-size: 20px; font-weight: 700; }
.m-stat span { font-size: 11px; opacity: .78; }
.m-stat.warn b { color: #f0b25a; }
.m-stat.bad { background: rgba(200,69,44,.35); }
.m-stat.bad b { color: #ff9d8a; }

.m-body { padding: 12px; display: flex; flex-direction: column; gap: 9px; }
.m-section {
  font-size: 12.5px; font-weight: 700; color: #3c4a45;
  padding: 6px 2px 0;
}
.m-section.bad { color: var(--red-text); }
.m-section.muted { color: var(--faint); font-weight: 600; }

.m-card {
  background: #fff; border-radius: 11px; padding: 12px 13px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
  cursor: pointer;
}
.m-card.red { box-shadow: inset 3px 0 0 var(--red), 0 1px 2px rgba(0,0,0,.06); }
.m-card.yellow { box-shadow: inset 3px 0 0 var(--yellow), 0 1px 2px rgba(0,0,0,.06); }
.m-card.green { box-shadow: inset 3px 0 0 var(--green-ok), 0 1px 2px rgba(0,0,0,.06); }
.m-card.unknown {
  box-shadow: inset 3px 0 0 var(--faint), 0 1px 2px rgba(0,0,0,.06);
  background: #fbfcfb;
}
.m-card-hd { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.m-po { font-weight: 700; font-size: 14px; color: var(--ink); }
.m-sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; line-height: 1.5; }
.m-note {
  margin-top: 9px; font-size: 12px; color: var(--muted);
  background: var(--page-2); border-radius: 8px; padding: 9px 10px;
}

.m-badge {
  border-radius: 5px; padding: 3px 8px; font-size: 11.5px;
  font-weight: 700; white-space: nowrap;
}
.m-badge.red { background: var(--red); color: #fff; }
.m-badge.yellow { background: var(--yellow-bg); color: var(--yellow-text); }
.m-badge.green { background: var(--green-ok-bg); color: var(--green-ok-text); }
.m-badge.unknown { background: #eef1f0; color: var(--muted); font-weight: 600; }

/* ปุ่มทุกปุ่มสูง >= 44px ตาม handoff (นิ้วโป้งกดได้ขณะเดิน) */
.m-actions { display: flex; gap: 8px; margin-top: 10px; }
.m-btn-main {
  flex: 1; min-height: 46px; border: 0; border-radius: 9px;
  background: var(--green); color: #fff; font: inherit;
  font-size: 13.5px; font-weight: 700; cursor: pointer;
}
.m-btn-main:disabled { opacity: .55; }
.m-btn-alt {
  min-height: 46px; padding: 0 15px; border-radius: 9px;
  border: 1px solid #cfd8d4; background: #fff; color: #3c4a45;
  font: inherit; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.m-btn-alt.wide { width: 100%; margin-top: 9px; }

.m-log { background: #fff; border-radius: 11px; padding: 12px 13px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.m-log-ft { display: flex; justify-content: space-between; align-items: center; margin-top: 9px; font-size: 11.5px; color: var(--faint); }

.m-add-log {
  border: 1.5px dashed #b7c4be; border-radius: 11px; min-height: 48px;
  background: none; color: var(--green); font: inherit; font-size: 13.5px;
  font-weight: 600; cursor: pointer; width: 100%;
}
.m-empty { padding: 26px 12px; text-align: center; color: var(--faint); font-size: 13.5px; }
.m-empty.small { padding: 14px 12px; font-size: 12.5px; }

/* แถบเมนูล่าง — โผล่เฉพาะจอแคบ */
.m-nav { display: none; }
@media (max-width: 760px) {
  .m-nav {
    position: fixed; left: 0; right: 0; bottom: 0;
    display: flex; justify-content: space-around;
    background: #fff; border-top: 1px solid var(--line);
    padding: 8px 0 12px; z-index: 30;
  }
  .m-nav a {
    text-align: center; font-size: 11px; color: var(--faint);
    min-width: 84px; min-height: 44px;
  }
  .m-nav a span { display: block; font-size: 19px; }
  .m-nav a.on { color: var(--green); font-weight: 700; }
  .wrap, .detail { padding-bottom: 80px; }
  .hdr .nav { display: none; }
}

/* บนมือถือ หน้า "งานของฉัน" มีชื่อผู้ใช้อยู่ในส่วนทักทายอยู่แล้ว
   แถบบนจึงเหลือแค่ปุ่มเมนูผู้ใช้ (ออกจากระบบ/เปลี่ยนรหัส) ไม่ต้องมีโลโก้ซ้ำ */
@media (max-width: 760px) {
  .hdr { padding: 8px 12px; gap: 8px; }
  .hdr .logo,
  .hdr .title,
  .hdr .sub { display: none; }
  .hdr > div:not(.me-box) { display: none; }
  .me-box .me { font-size: 12px; padding: 3px 5px 3px 12px; }
  .m-hd { padding-top: 10px; }
}

/* กล่องพิมพ์ข้อความแบบ bottom sheet (ใช้แทน prompt ที่มือถือบล็อก) */
.sheet-bg {
  position: fixed; inset: 0; background: rgba(15,40,34,.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 60;
}
.sheet {
  background: #fff; width: min(520px, 100%);
  border-radius: 16px 16px 0 0; padding: 10px 18px 20px;
  display: flex; flex-direction: column; gap: 11px;
  max-height: 88vh; overflow-y: auto;
}
@media (min-width: 620px) {
  .sheet-bg { align-items: center; }
  .sheet { border-radius: 14px; }
}
.sheet-grip {
  width: 40px; height: 4px; border-radius: 3px; background: #d8dfdc;
  align-self: center; margin-bottom: 4px;
}
.sheet h2 { margin: 0; font-size: 16px; color: var(--ink); }
.sheet-hint { margin: -6px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.sheet textarea {
  font: inherit; font-size: 15px; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 9px; resize: vertical;
  min-height: 96px;
}
.sheet textarea:focus { outline: 2px solid var(--green); outline-offset: -1px; }
.sheet-ft { display: flex; gap: 9px; }
.sheet-ft .m-btn-main { flex: 1; }

/* ================================================================ จัดการผู้ใช้ */
.urow {
  display: grid;
  grid-template-columns: 1.5fr 1.1fr 1.1fr 1.1fr .6fr 1.5fr;
  gap: 14px; align-items: center;
  padding: 12px 10px; border-bottom: 1px solid var(--line-soft);
  min-width: 940px; font-size: 13.5px;
}
.urow.head {
  font-size: 12px; color: var(--muted-2); font-weight: 600;
  border-bottom: 2px solid #dfe5e2;
}
.urow b { font-size: 14px; color: var(--ink); }
.usub { font-size: 12px; color: var(--faint); }
.uact { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
.btn-ghost.sm { padding: 6px 11px; font-size: 12.5px; min-height: 34px; }
.elog { padding: 9px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.elog:last-child { border-bottom: 0; }

/* ================================================================ ทะเบียนคุมหนังสือ */
.drow {
  display: grid;
  grid-template-columns: 108px 92px 1.7fr 1.1fr 1.1fr .9fr 1.1fr 1.3fr;
  gap: 14px; align-items: center;
  padding: 11px 10px; border-bottom: 1px solid var(--line-soft);
  min-width: 1140px; font-size: 13.5px;
}
.drow.head { font-size: 12px; color: var(--muted-2); font-weight: 600; border-bottom: 2px solid #dfe5e2; }
.drow.sysdraft { background: #fffdf3; }
.dno { font-weight: 700; color: var(--green); }
.dsubj { color: var(--ink-2); }
.dpo a { color: var(--green); font-weight: 600; }
.dpo a:hover { text-decoration: underline; }
.badge.info { background: var(--blue-bg); color: var(--blue); }
.latest-no {
  border: 1px dashed var(--line); border-radius: 9px; padding: 6px 14px;
  background: #fff; text-align: right;
}
.latest-no b { font-size: 15px; color: var(--green); }
select.mini {
  font: inherit; font-size: 12.5px; padding: 5px 8px;
  border: 1px solid var(--line); border-radius: 7px; background: #fff; color: #3c4a45;
}
.picklist { max-height: 46vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.pick {
  display: flex; gap: 11px; align-items: flex-start;
  border: 1px solid var(--line); border-radius: 9px; padding: 11px 12px;
  cursor: pointer; font-size: 13.5px;
}
.pick:hover { background: var(--page-2); }
.pick input { margin-top: 3px; width: 18px; height: 18px; flex: none; }
.pick b { color: var(--ink); }
textarea.memo {
  font-family: "Noto Sans Thai", serif; font-size: 14px; line-height: 1.75;
  background: #fffdf8;
}

/* ================================================================ ภาพรวมผู้บริหาร */
.ov { padding: 16px 20px 24px; }
.ov-head { margin-bottom: 14px; }
.ov-grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 14px; }
@media (max-width: 980px) { .ov-grid { grid-template-columns: 1fr; } }

/* กราฟคอขวดรายขั้นตอน */
.bar-row {
  display: grid; grid-template-columns: 108px 1fr 176px;
  gap: 12px; align-items: center; padding: 7px 0;
}
.bar-label { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.bar-track { background: var(--line-soft); border-radius: 4px; height: 16px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; }
.bar-fill.green { background: var(--green-ok); }
.bar-fill.yellow { background: var(--yellow); }
.bar-fill.red { background: var(--red); }
.bar-fill.unknown { background: repeating-linear-gradient(45deg, #c9d4cf, #c9d4cf 5px, #e4e9e6 5px, #e4e9e6 10px); }
.bar-val { font-size: 12.5px; color: var(--ink-2); }
.bar-val b { font-size: 14px; }
.bar-val .usub { display: block; }

/* แท่งภาระงานรายคน */
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-bottom: 12px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.sw.done { background: var(--green-ok); }
.sw.warn { background: var(--yellow); }
.sw.late { background: var(--red); }
.sw.unknown { background: repeating-linear-gradient(45deg, #c9d4cf, #c9d4cf 4px, #eef1f0 4px, #eef1f0 8px); }
.pbar-row {
  display: grid; grid-template-columns: 108px 1fr 168px;
  gap: 12px; align-items: center; padding: 8px 0;
}
.pbar-track { display: flex; height: 16px; border-radius: 4px; overflow: hidden; background: var(--line-soft); }
.seg { height: 100%; }
.seg.done { background: var(--green-ok); }
.seg.warn { background: var(--yellow); }
.seg.late { background: var(--red); }
.seg.unknown { background: repeating-linear-gradient(45deg, #c9d4cf, #c9d4cf 4px, #eef1f0 4px, #eef1f0 8px); }
.pbar-val { font-size: 12.5px; }
.pbar-val b { font-size: 14px; }
.pbar-val .usub { display: block; }
.cov.low { color: var(--red-text); font-weight: 600; }

/* การ์ดต้องติดตาม */
.card.alert { border-color: #f0d5cd; }
.card.alert h3 { color: var(--red-text); }
.late-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; cursor: pointer;
}
.late-row:hover { background: var(--page-2); }
.late-row b { color: var(--ink); }
.btn-danger.wide, .btn-ghost.wide {
  display: block; width: 100%; margin-top: 14px; text-align: center; text-decoration: none;
}
.mini-stats { display: flex; gap: 20px; margin-bottom: 12px; }
.mini-stats b { display: block; font-size: 20px; font-weight: 700; color: var(--ink); }
.mini-stats span { font-size: 12px; color: var(--faint); }
.mini-stats .bad b { color: var(--red); }

/* ================================================================ แจกงาน */
.assign-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 980px) { .assign-grid { grid-template-columns: 1fr; } }
.q-list { display: flex; flex-direction: column; gap: 9px; max-height: 62vh; overflow-y: auto; }
.q-card {
  background: #fffdf8; border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; display: flex; flex-direction: column; gap: 4px;
}
.q-card.unknown { background: #fbfcfb; border-style: dashed; }
.q-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.q-head b { font-size: 14px; color: var(--ink); cursor: pointer; }
.q-head b:hover { color: var(--green); text-decoration: underline; }
.q-assign {
  font: inherit; font-size: 13px; margin-top: 6px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; min-height: 40px;
}
.wl-row {
  display: grid; grid-template-columns: 120px 1fr 150px;
  gap: 12px; align-items: center; padding: 9px 0;
  border-bottom: 1px solid var(--line-soft);
}
.wl-row:last-child { border-bottom: 0; }
.wl-row.good { box-shadow: inset 3px 0 0 var(--green-ok); padding-left: 10px; }
.wl-row.bad  { box-shadow: inset 3px 0 0 var(--red); padding-left: 10px; }
.wl-row.warn { box-shadow: inset 3px 0 0 var(--yellow); padding-left: 10px; }
.wl-hint { font-size: 11.5px; margin-top: 3px; }
.wl-hint.good { color: var(--green-ok-text); font-weight: 600; }
.wl-hint.bad { color: var(--red-text); font-weight: 600; }
.wl-hint.warn { color: var(--yellow-text); }
.wl-bar { display: flex; height: 16px; border-radius: 4px; overflow: hidden; background: var(--line-soft); }
.wl-num { font-size: 12.5px; }
.wl-num b { font-size: 15px; }
.wl-num .usub { display: block; }
.round-row {
  display: grid; grid-template-columns: 1.6fr .6fr .8fr 1fr;
  gap: 10px; align-items: center; padding: 9px 0;
  border-bottom: 1px solid var(--line-soft); font-size: 13px;
}
.round-row:last-child { border-bottom: 0; }

/* ================================================================ MOIT / งบ */
.tracks-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; align-items: start; }
.tk-list { display: flex; flex-direction: column; }
.tk-row {
  display: grid; grid-template-columns: 14px 1fr auto;
  gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line-soft);
}
.tk-row:last-child { border-bottom: 0; }
.tk-dot { width: 11px; height: 11px; border-radius: 50%; margin-top: 5px; }
.tk-dot.green { background: var(--green-ok); }
.tk-dot.yellow { background: var(--yellow); }
.tk-dot.empty { background: var(--dot-empty); }
.tk-main b { font-size: 13.5px; color: var(--ink); }
.tk-main a { color: var(--green); font-weight: 600; }
.tk-act { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.bd-bar { display: flex; height: 18px; border-radius: 5px; overflow: hidden; background: var(--line-soft); margin-bottom: 8px; }
.bd-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.sw.empty { background: var(--line-soft); border: 1px solid var(--line); }

/* ================================================================ บันทึกการตรวจเอกสาร */
.rv-row {
  display: grid; grid-template-columns: 1fr 1.2fr 1.3fr; gap: 10px; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px;
}
.rv-row:last-child { border-bottom: 0; }
.rv-row b { color: var(--ink); font-size: 14px; }
.find-row {
  display: grid; grid-template-columns: 40px 1fr; gap: 10px;
  padding: 7px 0; border-bottom: 1px solid var(--line-soft); font-size: 12.5px; line-height: 1.6;
}
.find-row:last-child { border-bottom: 0; }
.find-n { font-weight: 700; color: var(--red-text); }
.rvw { padding: 9px 0; border-bottom: 1px solid var(--line-soft); font-size: 12.5px; }
.rvw:last-child { border-bottom: 0; }
.rvw b { color: var(--ink); margin-right: 7px; }

/* ---------------------------------------------- นาฬิกา SLA และจุดตรวจ (PROCESS.md) */
.sub-h { font-size: 14px; font-weight: 600; color: var(--ink); margin: 16px 0 8px; }
.wt-set, .wt-pick { padding: 10px 12px; background: var(--tint, #eef4f1); border-radius: 8px; margin-bottom: 12px; font-size: 14.5px; }
.wt-pick .btn-step { margin-right: 6px; }
.clocks { display: flex; flex-direction: column; gap: 10px; }
.clk { padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line, #dbe3df); background: #fff; }
.clk-label { font-size: 13px; color: var(--muted, #5b6b66); margin-bottom: 3px; }
.clk-val { font-size: 14.5px; }
.clk-val b { font-size: 17px; }
.clk-budget { color: var(--muted, #5b6b66); font-size: 13px; }
.clk-over { color: var(--red, #c8452c); font-weight: 600; margin-left: 6px; font-size: 13px; }
.clk-run { color: var(--muted, #5b6b66); font-size: 12.5px; margin-left: 6px; }
.clk-note { font-size: 13px; color: var(--muted, #5b6b66); }
.clk-bar { height: 4px; border-radius: 2px; background: #eceeed; margin-top: 6px; overflow: hidden; }
.clk-bar i { display: block; height: 100%; background: var(--green-ok-text, #2f8a4c); }
.clk.over { border-color: var(--red, #c8452c); background: #fdf3f1; }
.clk.over .clk-bar i { background: var(--red, #c8452c); }
.clk.bad { border-color: var(--yellow-text, #b07d15); background: #fbf6ea; }
.clk.muted { background: #fafbfa; }
.cps { display: flex; flex-direction: column; }
.cp { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid #eef1f0; }
.cp:first-child { border-top: 0; }
.cp-dot { width: 9px; height: 9px; border-radius: 50%; background: #d6dcd9; flex: none; }
.cp.on .cp-dot { background: var(--green-ok-text, #2f8a4c); }
.cp-body { flex: 1; font-size: 14.5px; }
.cp-date { margin-left: 8px; color: var(--muted, #5b6b66); font-size: 13.5px; }
.btn-ghost.sm { padding: 3px 10px; font-size: 13px; }
.pen { margin-top: 14px; padding: 10px 12px; border-radius: 8px; background: #fafbfa; border: 1px solid var(--line, #dbe3df); }
.pen.late { background: #fdf3f1; border-color: var(--red, #c8452c); }
.pay { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.rcpt { font-size: 14.5px; }

/* คำเตือนในการ์ดกระบวนการ — ใช้ตอนตัวเลขยังเชื่อได้ไม่เต็มที่ */
.callout-warn {
  background: var(--yellow-bg, #fbf6ea); border-left: 3px solid var(--yellow-text, #b07d15);
  border-radius: 0 8px 8px 0; padding: 9px 12px; margin-bottom: 12px;
  font-size: 13.5px; line-height: 1.6; color: var(--ink, #12312a);
}
.callout-warn .note { display: block; margin-top: 3px; }

/* วันหยุดราชการ (หน้าจัดการผู้ใช้) */
.hol-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.hol-form input[type=date] { width: 160px; }
.hol-form input[name=name] { flex: 1; min-width: 200px; }
.hol-list { display: flex; flex-direction: column; }
.hol-row {
  display: grid; grid-template-columns: 110px 1fr 90px auto; gap: 10px;
  align-items: center; padding: 7px 0; border-top: 1px solid #eef1f0; font-size: 14px;
}
.hol-row:first-child { border-top: 0; }

/* ---------------------------------------------- เส้นทางเรื่อง (การ์ดเดียวรวมกำหนดเวลา) */
.steps-tl { display: flex; flex-direction: column; }
.st {
  display: grid; grid-template-columns: 16px 1fr 90px; gap: 12px;
  padding: 12px 0; border-top: 1px solid #eef1f0; align-items: start;
}
.st:first-child { border-top: 0; }
.st-dot {
  width: 11px; height: 11px; border-radius: 50%; background: #d6dcd9;
  margin-top: 5px; flex: none; box-shadow: 0 0 0 3px #fff;
}
.st.on  .st-dot { background: var(--green-ok-text, #2f8a4c); }
.st.cur .st-dot { background: var(--yellow-text, #b07d15); box-shadow: 0 0 0 3px #fbf6ea; }
.st-name { font-size: 15px; font-weight: 600; color: var(--ink, #12312a); }
.st.cur .st-name { color: var(--yellow-text, #b07d15); }
.st-owner {
  font-size: 12px; font-weight: 500; color: var(--muted, #5b6b66);
  border: 1px solid var(--line, #dbe3df); border-radius: 20px; padding: 1px 8px; margin-left: 6px;
}
.st-facts { font-size: 13.5px; color: var(--muted, #5b6b66); margin-top: 3px; line-height: 1.6; }
.st-when { font-size: 13px; color: var(--muted, #5b6b66); text-align: right; padding-top: 2px; }
.st-age { font-size: 12.5px; font-weight: 600; margin-left: 8px; }
.st-age.red { color: var(--red, #c8452c); }
.st-age.yellow { color: var(--yellow-text, #b07d15); }
.st-age.green { color: var(--green-ok-text, #2f8a4c); }
.st-sep {
  font-size: 13px; color: var(--muted, #5b6b66); padding: 14px 0 8px;
  border-top: 2px solid var(--line, #dbe3df); margin-top: 8px;
}
.mclk {
  font-size: 13px; margin-top: 5px; padding: 5px 9px; border-radius: 6px;
  background: #fafbfa; border: 1px solid var(--line, #dbe3df); color: var(--ink, #12312a);
  display: inline-block; margin-right: 6px;
}
.mclk b { font-size: 14.5px; }
.mclk.over { background: #fdf3f1; border-color: var(--red, #c8452c); }
.mclk.done { background: var(--green-ok-bg, #eaf5ed); border-color: var(--green-ok-text, #2f8a4c); }
.mclk.bad  { background: #fbf6ea; border-color: var(--yellow-text, #b07d15); }
.mclk.muted { color: var(--muted, #5b6b66); }
.mclk-over { color: var(--red, #c8452c); font-weight: 600; margin-left: 4px; }
.mclk-note { color: var(--muted, #5b6b66); font-size: 12.5px; margin-left: 4px; }
.ok-text { color: var(--green-ok-text, #2f8a4c); font-weight: 600; }

@media (max-width: 720px) {
  .st { grid-template-columns: 14px 1fr; }
  .st-when { display: none; }
  .mclk { display: block; margin-right: 0; }
}


/* ---- หัวตารางที่กดจัดลำดับได้ ---- */
/* เป็น <button> ไม่ใช่ <div> เพื่อให้กด Tab ถึงและกด Enter ได้ */
.th-sort {
  font: inherit; font-size: 12px; font-weight: 600;
  color: var(--muted-2); background: none; border: 0;
  padding: 2px 0; margin: 0;
  display: flex; align-items: center; gap: 4px;
  text-align: left; cursor: pointer; border-radius: 4px;
}
.th-sort.num-cell { justify-content: flex-end; }
.th-sort:hover { color: var(--ink); }
.th-sort:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.th-sort.on { color: var(--green); }
.th-sort .arw { font-size: 9px; line-height: 1; }
/* กันหัวตารางขยับตอนลูกศรโผล่ */
.th-sort:not(.on) .arw::before { content: "95"; opacity: .25; font-size: 10px; }

/* ---- ช่องวันที่ในตาราง ---- */
.when-cell { font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
/* "ไม่มีข้อมูล" ต้องอ่านออกว่าไม่ใช่ค่าจริง แต่ต้องไม่จางจนมองไม่เห็น
   เพราะเป็นข้อมูลสำคัญ: ใบพวกนี้คือใบที่ระบบยังจับเวลาไม่ได้ */
.no-data { color: var(--faint); font-size: 11.5px; font-style: italic; }


/* ---- ช่องกรอกวันที่แบบไทย (public/thdate.js) ---- */
/* แทน <input type="date"> ที่เบราว์เซอร์บังคับรูปแบบเป็นภาษาเครื่อง
   ทำให้เจ้าหน้าที่เห็น "31-Aug-2026" แทนที่จะเป็น "31 ส.ค. 2569" */
.thd { position: relative; display: flex; align-items: stretch; }
.thd .thd-view {
  flex: 1; min-width: 0;
  font-variant-numeric: tabular-nums;
  border-top-right-radius: 0; border-bottom-right-radius: 0;
  border-right: 0;
}
/* วันที่อ่านไม่ออก — ต้องเห็นชัดว่ายังส่งไม่ได้ ไม่ใช่ปล่อยผ่านเป็นค่าว่าง */
.thd .thd-view.bad { border-color: var(--red); background: #fff5f4; }
.thd-open {
  flex: 0 0 auto; width: 40px;
  border: 1px solid var(--line); border-left: 1px solid var(--line-soft);
  border-top-right-radius: 8px; border-bottom-right-radius: 8px;
  background: var(--page-2); color: var(--muted);
  font-size: 13px; cursor: pointer;
}
.thd-open:hover { color: var(--ink); background: #eef2f0; }
.thd-open:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }

.thd-pop {
  position: absolute; z-index: 40; top: calc(100% + 4px); left: 0;
  /* พลิกขึ้นบน/ชิดขวาเมื่อที่ว่างไม่พอ ตั้งโดย place() ใน thdate.js */
  width: 268px; padding: 10px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 26px rgba(16, 40, 34, .16);
}
.thd-pop.up { top: auto; bottom: calc(100% + 4px); }
.thd-pop.right { left: auto; right: 0; }
.thd-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.thd-head b { font-size: 13.5px; color: var(--ink); }
.thd-nav {
  width: 30px; height: 30px; border: 1px solid var(--line);
  border-radius: 7px; background: #fff; cursor: pointer;
  font-size: 15px; line-height: 1; color: var(--ink-2);
}
.thd-nav:hover { background: var(--page-2); }
.thd-dow, .thd-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.thd-dow span { text-align: center; font-size: 10.5px; color: var(--faint); padding: 2px 0; }
.thd-cell {
  height: 32px; border: 0; border-radius: 7px; background: none;
  font: inherit; font-size: 12.5px; color: var(--ink-2); cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.thd-cell.thd-blank { cursor: default; }
.thd-cell:not(.thd-blank):hover { background: var(--page-2); }
/* วันนี้มีเส้นขอบ วันที่เลือกไว้ทึบ — ต่างกันชัดพอไม่ให้สับสนสองอย่างนี้ */
.thd-cell.today { box-shadow: inset 0 0 0 1px var(--green); color: var(--green); font-weight: 600; }
.thd-cell.on { background: var(--green); color: #fff; font-weight: 700; }
.thd-foot { display: flex; gap: 6px; margin-top: 8px; }
.thd-foot button {
  flex: 1; height: 30px; border: 1px solid var(--line); border-radius: 7px;
  background: #fff; font: inherit; font-size: 12px; color: var(--ink-2); cursor: pointer;
}
.thd-foot button:hover { background: var(--page-2); }

/* มือถือ — ปุ่มต้องกดโดนตามที่ UX.md กำหนด (อย่างน้อย 44px) */
@media (max-width: 560px) {
  .thd-pop { width: min(300px, calc(100vw - 40px)); }
  .thd-cell { height: 44px; font-size: 14px; }
  .thd-nav { width: 44px; height: 44px; }
  .thd-foot button { height: 44px; font-size: 13px; }
  .thd-open { width: 48px; }
}
