/* app.css — ฟอร์ม + หลังบ้าน + ล็อกอิน (หน้าใบ A4 มี CSS ของตัวเองใน reportDoc.js — ต้องตรงใบจริง ไม่ใช้ธีมนี้) */
:root {
  --bg: #f4f5fa; --card: #fff; --ink: #0f172a; --ink-2: #334155; --mute: #64748b; --faint: #94a3b8;
  --line: #e5e7ef; --line-2: #d4d8e3; --soft: #f8f9fc;
  --pri: #4f46e5; --pri-2: #6366f1; --pri-d: #4338ca; --pri-soft: #eef2ff; --pri-ring: rgba(99, 102, 241, .18);
  --ok: #059669; --ok-d: #047857; --ok-soft: #ecfdf5;
  --warn: #b45309; --warn-soft: #fffbeb; --warn-line: #fde68a;
  --err: #dc2626; --err-soft: #fef2f2;
  --green: #d9ead3; /* สีช่องเขียวตามใบจริง */
  --r: 16px; --r-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 20px -8px rgba(15, 23, 42, .10);
  --shadow-lg: 0 18px 40px -16px rgba(15, 23, 42, .28);
  --font: "IBM Plex Sans Thai", "Sarabun", system-ui, "Segoe UI", Tahoma, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
body { background: radial-gradient(1200px 400px at 10% -10%, #e9e8ff 0%, transparent 60%), radial-gradient(900px 360px at 100% 0%, #e3f2ff 0%, transparent 55%), var(--bg); background-attachment: fixed; }
a { color: var(--pri); }
kbd { font: 12px ui-monospace, monospace; background: #fff; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; }
.ic { flex: none; display: inline-block; vertical-align: -3px; }
[hidden] { display: none !important; }

/* ── แถบบน ── */
.top { position: sticky; top: 0; z-index: 6; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-height: 58px; padding: 8px max(16px, calc((100% - 1240px) / 2 + 16px));
  background: rgba(255, 255, 255, .82); backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; text-decoration: none; font-size: 16.5px; letter-spacing: -.01em; }
.logo { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; color: #fff; background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); box-shadow: 0 6px 14px -6px rgba(99, 102, 241, .8); }
.top .crumb { color: var(--mute); font-size: 14px; }
.top .crumb b { color: var(--ink); font-weight: 600; }
.top .lnk { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); text-decoration: none; font-size: 14px; font-weight: 500; padding: 7px 10px; border-radius: 9px; }
.top .lnk:hover { background: var(--pri-soft); color: var(--pri-d); }
.top .btn { text-decoration: none; }
.top form.logout { margin: 0; display: inline-flex; }
/* หน้าเคส (มีเลขเคส+สถานะในหัว): จอกลางเหลือแค่ไอคอนเมนู ให้หัวอยู่แถวเดียว */
@media (max-width: 1180px) { .top .crumb ~ .mainnav a span { display: none; } .top .crumb ~ .mainnav { margin-left: 0; } }
.top button.lnk { border: 0; background: transparent; font: inherit; cursor: pointer; }
@media (max-width: 640px) { .top { gap: 8px; } .top .lnk span, .brand > span:not(.logo) { display: none; } }
.sp { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: #eef0f5; color: #475569; white-space: nowrap; }
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.chip.open { background: #fff7e6; color: #b45309; }
.chip.closed { background: var(--ok-soft); color: var(--ok-d); }
.chip.cancelled { background: var(--err-soft); color: #b91c1c; }

/* ── แถบขั้นตอน 1 → 2 → 3 ── */
.stepper { position: sticky; top: 58px; z-index: 5; display: flex; align-items: center; padding: 10px max(16px, calc((100% - 1240px) / 2 + 16px));
  background: rgba(255, 255, 255, .7); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); overflow-x: auto; }
.stepper button { flex: 1 1 0; min-width: 0; display: flex; align-items: center; gap: 12px; font: inherit; text-align: left; border: 0; background: transparent; padding: 8px 12px; border-radius: 12px; cursor: pointer; color: var(--mute); transition: background .15s; }
.stepper button:hover { background: rgba(99, 102, 241, .06); }
.stepper button i { flex: none; position: relative; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--line-2); font-style: normal; font-weight: 700; color: var(--mute); background: #fff; transition: all .2s; }
.stepper button span { display: grid; min-width: 0; }
.stepper button b { font-size: 15px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.stepper button small { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stepper button.done i { border-color: var(--ok); background: var(--ok); color: transparent; }
.stepper button.done i::after { content: ''; position: absolute; width: 10px; height: 6px; border-left: 2.5px solid #fff; border-bottom: 2.5px solid #fff; transform: translateY(-2px) rotate(-45deg); }
.stepper button.on { background: #fff; box-shadow: var(--shadow); }
.stepper button.on i { border-color: var(--pri); background: linear-gradient(135deg, #6366f1, #4f46e5); color: #fff; box-shadow: 0 0 0 5px var(--pri-ring); }
.stepper button.on.done i::after { content: none; }
.stepper button.on b { color: var(--pri-d); }
.stepper .sep { flex: 0 0 32px; height: 2px; border-radius: 2px; background: var(--line-2); margin: 0 4px; }
.stepper button.done + .sep { background: linear-gradient(90deg, var(--ok), var(--line-2)); }
/* หัวหน้าตัดเป็น 2 แถวได้ (เมนู) — แถบขั้นตอนไม่ติดบนจอ กันซ้อนหัว */
@media (max-width: 1100px) { .stepper { top: 0; position: relative; } }
@media (max-width: 720px) {
  .stepper { top: 0; position: relative; padding: 8px; }
  .stepper button { flex-direction: column; gap: 5px; text-align: center; padding: 6px 4px; }
  .stepper button span { justify-items: center; }
  .stepper button b { font-size: 13px; white-space: normal; line-height: 1.3; }
  .stepper button small { display: none; }
  .stepper .sep { flex-basis: 14px; margin: -22px 0 0; }
}

/* ── เนื้อหา / การ์ด ── */
.wrap { max-width: 1240px; margin: 0 auto; padding: 22px 16px 130px; display: grid; gap: 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; min-width: 0; box-shadow: var(--shadow); }
.card h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.card-h { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.card-h .badge, .card-h .chip { margin-left: auto; }
.tile { flex: none; display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; }
.tile.indigo { background: var(--pri-soft); color: var(--pri); }
.tile.sky { background: #e0f2fe; color: #0284c7; }
.tile.emerald { background: var(--ok-soft); color: var(--ok); }
.tile.amber { background: #fef3c7; color: #d97706; }
.tile.violet { background: #f3e8ff; color: #9333ea; }
.hint { color: var(--mute); font-size: 13.5px; margin: 0 0 12px; }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 18px; align-items: start; }
@media (max-width: 980px) { .cols { grid-template-columns: minmax(0, 1fr); } }

/* ── ช่องกรอก ── */
input, textarea, select { width: 100%; font: inherit; color: inherit; background: #fff; border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 9px 12px; transition: border-color .15s, box-shadow .15s; }
input:hover, textarea:hover, select:hover { border-color: #b9bfcd; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--pri-2); box-shadow: 0 0 0 4px var(--pri-ring); }
textarea { resize: vertical; }
#src { min-height: 360px; line-height: 1.65; font-size: 14.5px; background: #fbfbfe; }
.fld { display: grid; grid-template-columns: 120px minmax(0, 1fr); align-items: center; gap: 10px; margin: 0 0 10px; }
.fld > span { font-size: 14px; color: var(--ink-2); font-weight: 500; }
.fld.wide { align-items: start; }
.fld.wide > span { padding-top: 9px; }
@media (max-width: 640px) { .fld, .fld.wide { grid-template-columns: minmax(0, 1fr); gap: 4px; } .fld.wide > span { padding-top: 0; } }
.flash { animation: flash 1.4s ease-out; }
@keyframes flash { 0% { background-color: #fde68a; } 100% { } }
details.more summary, details.hist summary { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--ink-2); font-size: 14px; font-weight: 500; list-style: none; }
details.more summary::-webkit-details-marker, details.hist summary::-webkit-details-marker { display: none; }
details.more summary::after, details.hist summary::after { content: '▾'; margin-left: auto; color: var(--faint); transition: transform .2s; }
details[open].more summary::after, details[open].hist summary::after { transform: rotate(180deg); }
details.more[open] summary { margin-bottom: 14px; }
details.hist ol { margin: 12px 0 0; padding-left: 22px; color: var(--ink-2); font-size: 14px; }
details.hist li { margin: 3px 0; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.msg { font-size: 14px; color: var(--mute); }
.msg.ok { color: var(--ok-d); font-weight: 500; }
.msg.warn { color: var(--warn); }
.msg.err { color: var(--err); font-weight: 600; }
.badge { display: inline-flex; align-items: center; padding: 3px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: #eef0f5; color: #475569; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok-d); }
.badge.warn { background: #fff7e6; color: var(--warn); }

/* ── ปุ่ม ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-size: 14.5px; font-weight: 600; min-height: 40px; border: 1px solid var(--line-2); background: #fff; color: var(--ink-2);
  border-radius: 11px; padding: 0 16px; cursor: pointer; white-space: nowrap; text-decoration: none; transition: background .15s, box-shadow .15s, transform .05s, border-color .15s; box-shadow: 0 1px 2px rgba(15, 23, 42, .05); }
.btn:hover { background: var(--soft); border-color: #b9bfcd; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--pri-ring); }
.btn.pri { border-color: transparent; color: #fff; background: linear-gradient(180deg, #6366f1 0%, #4f46e5 100%); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), 0 8px 18px -8px rgba(79, 70, 229, .75); }
.btn.pri:hover { background: linear-gradient(180deg, #5b5ef0 0%, #4338ca 100%); }
.btn.ok { border-color: transparent; color: #fff; background: linear-gradient(180deg, #10b981 0%, #059669 100%); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), 0 8px 18px -8px rgba(5, 150, 105, .75); }
.btn.ok:hover { background: linear-gradient(180deg, #0ea472 0%, #047857 100%); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--err); font-weight: 500; box-shadow: none; }
.btn.ghost:hover { background: var(--err-soft); }
.btn.plain { border-color: transparent; background: transparent; color: var(--mute); font-weight: 500; box-shadow: none; }
.btn.plain:hover { background: #eef0f5; color: var(--ink-2); }
.btn.big { min-height: 46px; padding: 0 22px; font-size: 15.5px; border-radius: 13px; }
.btn.block { width: 100%; min-height: 52px; border: 2px dashed #c7d2fe; background: #f7f8ff; color: var(--pri-d); box-shadow: none; }
.btn.block:hover { background: var(--pri-soft); border-color: var(--pri-2); }
.btn.block small { font-weight: 400; color: var(--mute); font-size: 13px; }
.btn:disabled { opacity: .55; cursor: wait; }

/* ── ช่องรูป ── */
.slots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
@media (max-width: 1100px) { .slots { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.slot { border-radius: 14px; outline: none; }
.slot-lab { font-size: 13.5px; font-weight: 500; margin: 0 0 6px 2px; color: var(--ink-2); }
.drop { position: relative; height: 158px; border: 1.5px dashed var(--line-2); border-radius: 14px; background: var(--soft); display: grid; place-items: center; overflow: hidden; cursor: pointer; transition: border-color .15s, background .15s, box-shadow .15s; }
.drop:hover { border-color: var(--pri-2); background: #f7f8ff; }
.slot.has .drop { border: 1px solid var(--line); background: #0f172a; }
.slot:focus-visible .drop, .slot.over .drop { border-color: var(--pri-2); background: var(--pri-soft); box-shadow: 0 0 0 4px var(--pri-ring); }
.slot.sel .drop { border-color: var(--pri); box-shadow: 0 0 0 4px var(--pri-ring); }
.drop img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: grab; }
.drop .empty { display: grid; justify-items: center; gap: 2px; color: var(--mute); text-align: center; font-size: 14px; font-weight: 500; }
.drop .empty .ic { color: var(--faint); margin-bottom: 4px; }
.drop:hover .empty .ic { color: var(--pri-2); }
.drop .empty small { font-size: 12px; font-weight: 400; color: var(--faint); }
.drop .tools { position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; opacity: 0; transform: translateY(-4px); transition: opacity .15s, transform .15s; }
.slot:hover .drop .tools, .slot.sel .drop .tools, .slot:focus-within .drop .tools { opacity: 1; transform: none; }
@media (hover: none) { .drop .tools { opacity: 1; transform: none; } }
.drop .tools button { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 9px; background: rgba(255, 255, 255, .92); color: var(--ink); cursor: pointer; box-shadow: 0 2px 8px rgba(15, 23, 42, .25); backdrop-filter: blur(6px); }
.drop .tools button:hover { background: #fff; color: var(--pri); }
.drop .tools button[data-act="remove"]:hover { color: var(--err); }
.drop .busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255, 255, 255, .82); font-weight: 600; color: var(--pri); backdrop-filter: blur(2px); }
@media (max-width: 640px) { .drop { height: 128px; } }

/* ── ขั้นตรวจ ── */
.check, .paystep { display: grid; gap: 18px; }
.todo, .check .extra, .check details.more, .paystep > * { width: 100%; max-width: 920px; margin: 0 auto; }
.todo { display: flex; gap: 12px; padding: 14px 16px; border-radius: 14px; font-size: 14px; border: 1px solid; box-shadow: var(--shadow); }
.todo.warn { background: linear-gradient(180deg, #fffdf5, #fffbeb); border-color: var(--warn-line); }
.todo.ok { background: linear-gradient(180deg, #f6fffb, #ecfdf5); border-color: #a7f3d0; color: var(--ok-d); }
.todo-ic { flex: none; padding-top: 1px; }
.todo.warn .todo-ic { color: #d97706; }
.todo-b { min-width: 0; flex: 1; }
.todo-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; }
.todo-h b { font-size: 15px; font-weight: 600; }
.todo.warn .todo-h b { color: #92400e; }
.todo-h small { color: var(--mute); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chipbtn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 13.5px; font-weight: 500; border: 1px solid #fcd34d; background: #fff; color: #92400e; border-radius: 999px; padding: 4px 12px; cursor: pointer; transition: background .15s, transform .05s; }
.chipbtn:hover { background: #fef3c7; }
.chipbtn:active { transform: translateY(1px); }
.extra { padding: 12px 16px; border-radius: 14px; background: var(--warn-soft); border: 1px solid var(--warn-line); font-size: 14px; }
.extra ul { margin: 8px 0 0; padding-left: 20px; }
details.extra summary { cursor: pointer; font-weight: 600; color: #92400e; }

/* ใบตรวจ — หน้าตาเดียวกับใบ "บันทึก" A4 (กรอบดำ/สีช่องตามใบจริง) แต่แก้ในช่องได้ */
.sheet-edit { width: 100%; max-width: 920px; margin: 0 auto; background: #fff; border-radius: 6px; box-shadow: 0 0 0 1px rgba(15, 23, 42, .06), var(--shadow-lg); padding: 34px 38px 38px; }
.se-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 14px; }
.se-row { display: grid; grid-template-columns: 132px minmax(0, 1fr); align-items: center; }
.se-row > span { font-size: 14.5px; padding-right: 6px; color: var(--ink); }
.se-row.r0, .se-title.r0 { min-height: 46px; align-items: end; }
.se-title { display: flex; padding-bottom: 7px; }
.se-title b { border: 1px solid #9fc5e8; background: #cfe2f3; padding: 2px 22px; font-size: 18px; font-weight: 700; }
.cell { border: 1px solid #1f2937; border-radius: 0; margin-top: -1px; padding: 5px 9px; font-size: 15px; min-height: 34px; background: #fff; transition: background .15s; }
.cell:hover { border-color: #1f2937; }
.cell:focus { border-color: #1f2937; box-shadow: none; outline: 2px solid var(--pri-2); outline-offset: -1px; position: relative; z-index: 1; }
.cell.green { background: var(--green); }
.cell.gray { background: #efefef; }
.cell.miss { background: #fef9c3; }
.cell.short { max-width: 200px; }
.cell::placeholder { color: #b8b2a7; }
textarea.cell { min-height: 60px; }
.se-body { display: grid; gap: 12px; margin-top: 22px; }
.se-body .se-row.tall { align-items: start; }
.se-body .se-row.tall > span { padding-top: 7px; }
.se-photos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 14px; margin-top: 24px; }
.slot.se { border-radius: 0; }
.slot.se .slot-lab { margin: 0 0 4px 10px; font-weight: 400; color: var(--ink); font-size: 14px; }
.slot.se .drop, .slot.se.has .drop { height: 210px; border: 1px solid #1f2937; border-radius: 0; background: #fff; }
.slot.se .drop img { object-fit: contain; }
.slot.se:nth-child(2n) .drop { border-left: 0; }
.slot.se:not(.has) .drop { background: #fef9c3; }
.slot.se.sel .drop, .slot.se.over .drop { box-shadow: inset 0 0 0 3px var(--pri-2); }
@media (max-width: 720px) {
  .sheet-edit { padding: 18px 12px 22px; }
  .se-head { grid-template-columns: minmax(0, 1fr); }
  .se-row { grid-template-columns: 112px minmax(0, 1fr); }
  .se-col + .se-col .se-title { display: none; }
  .se-photos { grid-template-columns: minmax(0, 1fr); }
  .slot.se:nth-child(2n) .drop { border-left: 1px solid #1f2937; }
  .slot.se .drop, .slot.se.has .drop { height: 190px; }
}

/* ── ปิดงาน ── */
.pay { background: linear-gradient(180deg, #ffffff 0%, #fbfffd 100%); }
.pay-sum { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 15.5px; font-weight: 600; margin: 10px 0 8px; padding: 12px 14px; border-radius: 12px; background: var(--soft); border: 1px solid var(--line); }
.grid-pay { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) 230px; gap: 0 20px; align-items: start; margin-top: 6px; }
.grid-pay .fld.wide { grid-column: 1 / 3; }
.grid-pay .slip { grid-column: 3; grid-row: 1 / 4; }
.grid-pay .slip .drop { height: 150px; }
@media (max-width: 860px) { .grid-pay { grid-template-columns: minmax(0, 1fr); } .grid-pay .fld.wide, .grid-pay .slip { grid-column: auto; grid-row: auto; } }
.danger { text-align: right; }

/* ── แถบปุ่มล่าง (ลอย) ── */
.actions { position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 6; width: min(1208px, calc(100% - 24px)); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px;
  background: rgba(255, 255, 255, .88); backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-lg); }
.actions .msg { min-width: 0; padding-left: 4px; }
.actions .msg:empty { display: none; }
@media (max-width: 640px) {
  .actions { left: 0; right: 0; bottom: 0; transform: none; width: auto; border-radius: 18px 18px 0 0; gap: 6px; padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); }
  .actions .msg { order: -1; flex-basis: 100%; font-size: 13px; }
  .actions .sp { display: none; }
  .actions .btn { flex: 1 1 auto; padding: 0 12px; }
  .actions #backBtn, .actions #saveBtn { flex: 0 0 auto; }
  .actions .btn.big { flex: 1 1 60%; order: 1; }
}

/* ── หลังบ้าน ── */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.filters label { display: grid; gap: 4px; font-size: 13px; font-weight: 500; color: var(--mute); }
.filters input, .filters select { width: auto; min-width: 150px; }
.filters input[type=search] { min-width: 260px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.stat { display: flex; align-items: center; gap: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 24px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.stat span:not(.tile) { color: var(--mute); font-size: 13px; }
.tbl-wrap { overflow-x: auto; margin: -4px; padding: 4px; }
table.list { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
table.list th, table.list td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th { background: var(--soft); font-weight: 600; font-size: 12.5px; color: var(--mute); white-space: nowrap; letter-spacing: .02em; }
table.list th:first-child { border-top-left-radius: 10px; }
table.list th:last-child { border-top-right-radius: 10px; }
table.list tr:last-child td { border-bottom: 0; }
table.list td.num, table.list th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.list tr:hover td { background: #fafbff; }
table.list td.nowrap { white-space: nowrap; }
table.list a { font-weight: 600; text-decoration: none; }
table.list a:hover { text-decoration: underline; }
table.list a.doc { display: inline-flex; align-items: center; gap: 4px; font-weight: 500; padding: 3px 9px; border-radius: 8px; background: var(--pri-soft); }
table.list a.doc:hover { text-decoration: none; background: #e0e7ff; }
table.list .sub { color: var(--mute); font-size: 13px; }
.empty-list { padding: 36px; text-align: center; color: var(--mute); }

/* ── ล็อกอิน ── */
body.login { display: grid; min-height: 100vh; place-items: center; background: radial-gradient(800px 500px at 20% 10%, #c7d2fe 0%, transparent 60%), radial-gradient(700px 500px at 90% 90%, #ddd6fe 0%, transparent 60%), #eef0fb; }
body.login form { background: rgba(255, 255, 255, .9); backdrop-filter: blur(10px); padding: 34px 32px; border-radius: 22px; width: min(370px, 92vw); border: 1px solid #fff; box-shadow: var(--shadow-lg); }
body.login .logo { width: 46px; height: 46px; border-radius: 14px; margin-bottom: 14px; }
body.login h1 { font-size: 21px; margin: 0 0 4px; letter-spacing: -.01em; }
body.login p { color: var(--mute); font-size: 14px; margin: 0 0 20px; }
body.login p.err { color: var(--err); margin: 0 0 12px; font-weight: 500; }
body.login input { padding: 12px 14px; }
body.login button { width: 100%; margin-top: 14px; min-height: 46px; border: 0; border-radius: 12px; color: #fff; font: inherit; font-weight: 600; cursor: pointer; background: linear-gradient(180deg, #6366f1 0%, #4f46e5 100%); box-shadow: 0 10px 22px -10px rgba(79, 70, 229, .8); }

/* ── ขั้น 3 ส่งเข้ากลุ่มไลน์ ── */
.sendstep { display: grid; gap: 18px; }
.sendstep > .todo { max-width: none; }
.send-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 18px; align-items: start; }
@media (max-width: 980px) { .send-grid { grid-template-columns: minmax(0, 1fr); } }
.sendstep .fld { grid-template-columns: 112px minmax(0, 1fr); }
.sendstep .fld input.miss, .sendstep .fld textarea.miss { background: #fef9c3; border-color: #facc15; }
@media (max-width: 640px) { .sendstep .fld { grid-template-columns: minmax(0, 1fr); } }
.tile.line { background: #e8f9ef; color: #06c755; }
.btn.line { border-color: transparent; color: #fff; background: linear-gradient(180deg, #19d168 0%, #06c755 100%); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2), 0 8px 18px -8px rgba(6, 199, 85, .8); }
.btn.line:hover { background: linear-gradient(180deg, #12c260 0%, #05b34c 100%); }
/* หน้าตาแชตไลน์ */
.chat { display: grid; gap: 12px; padding: 16px 14px; margin-top: 8px; border-radius: 14px; background: #f1f3f6; border: 1px solid var(--line); }
.msgrow { display: grid; grid-template-columns: 34px minmax(0, 1fr); column-gap: 8px; align-items: start; }
.msgrow .av { grid-row: 1 / 3; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: #fff; background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.bub { justify-self: start; max-width: 100%; background: #fff; border-radius: 4px 18px 18px 18px; box-shadow: 0 1px 1px rgba(15, 23, 42, .06); font-size: 14.5px; line-height: 1.55; }
.bub.txt { padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bub .tag { color: #2563eb; font-weight: 500; }
.bub.pic { padding: 6px; border-radius: 4px 14px 14px 14px; }
.kitimg { display: grid; place-items: center; gap: 8px; min-height: 120px; min-width: 220px; color: var(--mute); font-size: 13.5px; text-align: center; padding: 10px; }
.kitimg img { display: block; width: 260px; max-width: 100%; border-radius: 8px; border: 1px solid var(--line); }
.kiterr { color: var(--err); font-weight: 500; }
.spin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid #e0e7ff; border-top-color: var(--pri); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.bub.file { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-width: 220px; }
.bub.file .pdfic { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 10px; background: #fef2f2; color: #dc2626; }
.bub.file b { display: block; font-size: 15px; }
.bub.file small { color: var(--mute); font-size: 12.5px; }
.partbtn { justify-self: start; display: inline-flex; align-items: center; gap: 5px; margin-top: 5px; font: inherit; font-size: 12.5px; font-weight: 500; color: var(--mute); background: transparent; border: 0; padding: 3px 6px; border-radius: 7px; cursor: pointer; }
.partbtn:hover { background: #e5e7ef; color: var(--ink-2); }
.msgrow.done .partbtn { color: var(--ok-d); }
.msgrow.done .partbtn::after { content: '✓ แล้ว'; font-weight: 600; }
.msgrow.done .bub { box-shadow: 0 0 0 2px #a7f3d0; }
.how { margin: 12px 2px 0; }

/* ── หลังบ้าน: เมนูบน ── */
.wrap.wide { max-width: 1400px; }
.mainnav { display: flex; gap: 2px; margin-left: 8px; overflow-x: auto; }
.mainnav a { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 10px; color: var(--ink-2); text-decoration: none; font-size: 14.5px; font-weight: 500; white-space: nowrap; }
.mainnav a:hover { background: var(--pri-soft); color: var(--pri-d); }
.mainnav a.on { background: var(--pri-soft); color: var(--pri-d); font-weight: 600; }
@media (max-width: 760px) { .mainnav { order: 9; flex-basis: 100%; margin: 4px 0 0; } }

/* สถานะเคส + ธง */
.stage { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; background: #eef0f5; color: #475569; }
.stage.gray { background: #eef0f5; color: #475569; }
.stage.amber { background: #fff4dc; color: #b45309; }
.stage.sky { background: #e0f2fe; color: #0369a1; }
.stage.indigo { background: var(--pri-soft); color: var(--pri-d); }
.stage.violet { background: #f3e8ff; color: #7e22ce; }
.stage.emerald { background: var(--ok-soft); color: var(--ok-d); }
.stage.red { background: var(--err-soft); color: #b91c1c; }
.chip.stage::before { display: none; }
.flag { display: inline-block; margin: 4px 4px 0 0; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.flag.red { background: #fee2e2; color: #b91c1c; }
.flag.amber { background: #fef3c7; color: #92400e; }
.flag.violet { background: #f3e8ff; color: #7e22ce; }
.flag.sky { background: #e0f2fe; color: #0369a1; }
.flags { margin: -4px 0 10px; }

/* ── ติดตามช่าง ── */
.pipeline { display: flex; align-items: stretch; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.pipe { flex: 1 1 0; min-width: 120px; display: grid; gap: 2px; padding: 12px 14px; border-radius: 14px; background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow); text-decoration: none; color: var(--ink-2); border-top: 4px solid #cbd5e1; }
.pipe b { font-size: 26px; line-height: 1.1; color: var(--ink); }
.pipe span { font-size: 13px; }
.pipe:hover { border-color: var(--pri-2); }
.pipe.on { box-shadow: 0 0 0 3px var(--pri-ring); border-color: var(--pri-2); }
.pipe.gray { border-top-color: #94a3b8; }
.pipe.amber { border-top-color: #f59e0b; }
.pipe.sky { border-top-color: #0ea5e9; }
.pipe.indigo { border-top-color: var(--pri); }
.pipe.violet { border-top-color: #a855f7; }
.pipe.emerald { border-top-color: var(--ok); }
.pipe-arrow { align-self: center; color: var(--faint); flex: none; }
.alert-late { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 16px; border-radius: 14px; background: linear-gradient(180deg, #fff5f5, #fef2f2); border: 1px solid #fecaca; color: #991b1b; text-decoration: none; box-shadow: var(--shadow); }
.alert-late b { font-size: 16px; }
.alert-late span { font-size: 13.5px; color: #b45353; }
.alert-late.on { box-shadow: 0 0 0 3px rgba(239, 68, 68, .2); }
.filters label.chk { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-2); padding-bottom: 9px; }
.filters label.chk input { width: auto; min-width: 0; }
/* คอม: คอลัมน์คงที่ ทุกช่องชิดบน (แถวสูงไม่เท่ากันก็อ่านเป็นแนวเดียว) · จอแคบกว่า 1100 เลื่อนตารางซ้าย-ขวาในกรอบ */
table.track { table-layout: fixed; min-width: 960px; }
table.track col.w-case { width: 16%; } table.track col.w-model { width: 19%; } table.track col.w-tech { width: 16%; } table.track col.w-recv { width: 9%; }
table.track col.w-appt { width: 13%; } table.track col.w-st { width: 13%; } table.track col.w-note { width: 14%; }
table.track td.c-acts { display: none; }
table.track td { vertical-align: top; padding-top: 12px; padding-bottom: 12px; overflow-wrap: anywhere; }
table.track td.c-case a.no b { font-size: 15px; }
table.track .cust { font-weight: 500; }
.wchip { display: inline-block; white-space: nowrap; padding: 0 7px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef0f5; color: #475569; vertical-align: 1px; }
.wchip.in { background: var(--ok-soft); color: var(--ok-d); }
.wchip.out { background: #fce7f3; color: #be185d; }   /* นอกประกัน = ชมพู (ส้ม/เหลืองใช้กับธง "เกิน 3 วัน" แล้ว) */
.wchip.may { background: #f3e8ff; color: #7e22ce; }
.clip2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
table.track input { padding: 6px 9px; font-size: 14px; width: 100%; }
table.track .tels { display: flex; flex-direction: column; gap: 2px; }
table.track .vis { display: flex; align-items: center; gap: 4px; color: var(--pri-d); font-size: 12.5px; font-weight: 600; }
table.track .visbtn { margin-top: 6px; width: 100%; }
table.track .tline { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; }
.linkbtn { display: inline-flex; align-items: center; gap: 4px; margin: 2px 0; padding: 0; border: 0; background: transparent; font: inherit; font-size: 12.5px; font-weight: 500; color: var(--mute); cursor: pointer; }
.linkbtn:hover { color: var(--pri-d); }
table.track .flags { margin: 6px 0 0; display: flex; flex-wrap: wrap; gap: 4px; }
table.track .flags .flag { margin: 0; white-space: normal; }
table.track tr.late td { background: #fffafa; }
table.track tr.late td:first-child { box-shadow: inset 3px 0 0 #ef4444; }
/* ช่องวันที่แบบไทย: ข้อความ วัน/เดือน/ปี + ช่อง date จริงใส ๆ ทับ (กดตรงไหนก็เปิดปฏิทิน) */
.dbox { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 36px; padding: 6px 10px; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: #fff; color: var(--ink); font-size: 14px; cursor: pointer; }
.dbox.empty .dv { color: var(--faint); }
.dbox .ic { color: var(--mute); }
.dbox input[type="date"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; padding: 0; border: 0; }
.dbox:focus-within { border-color: var(--pri-2); box-shadow: 0 0 0 4px var(--pri-ring); }
table.track tr.saving { opacity: .55; }
table.track tr.flash td { animation: flash 1.4s ease-out; }
.tech { font-weight: 600; }
.tel { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; font-weight: 600; text-decoration: none; color: var(--pri-d); }
.addtel { font-size: 12.5px; font-weight: 500; text-decoration: none; color: var(--mute); }
.addtel:hover { color: var(--pri-d); }
.pick { display: inline-flex; align-items: center; gap: 5px; font-size: 13.5px; font-weight: 600; text-decoration: none; color: #b45309; padding: 4px 10px; border-radius: 8px; background: #fff7e6; }
.clip { max-width: 260px; }
td.acts { white-space: nowrap; text-align: right; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; border-radius: 9px; gap: 5px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20; padding: 10px 18px; border-radius: 12px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow-lg); }
.toast.ok { background: #064e3b; color: #ecfdf5; }
.toast.err { background: #7f1d1d; color: #fef2f2; }
@media (max-width: 760px) {
  /* มือถือ: แถว = การ์ด 2 คอลัมน์ (เห็นหลายเคสต่อจอ) · เลขเคส|สถานะ · รุ่น/อาการ · ช่าง · รับเรื่อง|นัด · หมายเหตุ · ปุ่ม (สูง 44px กดง่าย) */
  table.track { min-width: 0; table-layout: auto; }
  table.track thead, table.track colgroup { display: none; }
  table.track, table.track tbody { display: block; width: 100%; }
  table.track tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "case st" "model model" "tech recv" "appt appt" "note note" "acts acts";
    gap: 8px 12px; border: 1px solid var(--line); border-radius: 14px; margin-bottom: 10px; padding: 12px; background: #fff; }
  table.track tr.late { border-left: 4px solid #ef4444; }
  table.track tr.late td, table.track tr.late td:first-child { background: transparent; box-shadow: none; }
  table.track td { display: block; border: 0; padding: 0; min-width: 0; }
  table.track .c-case { grid-area: case; } table.track .c-st { grid-area: st; justify-self: end; text-align: right; }
  table.track .c-st .flags { justify-content: flex-end; }
  table.track .c-model { grid-area: model; } table.track .c-tech { grid-area: tech; } table.track .c-recv { grid-area: recv; }
  table.track .c-appt { grid-area: appt; } table.track .c-note { grid-area: note; } table.track .c-acts { grid-area: acts; }
  table.track td[data-l]::before { content: attr(data-l); display: block; font-size: 12px; font-weight: 600; color: var(--mute); margin-bottom: 2px; }
  table.track .c-tech .tels { flex-direction: row; flex-wrap: wrap; gap: 4px 12px; }
  table.track .tel { min-height: 40px; font-size: 16px; }
  table.track input, table.track .dbox { min-height: 44px; font-size: 16px; }
  /* นัด: ช่องวันที่ + ปุ่มช่างเข้าแล้ว บรรทัดเดียวกัน · เปิดเคส ชิดขวาเล็ก ๆ */
  table.track td.c-appt { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
  table.track td.c-appt::before { flex-basis: 100%; margin-bottom: 0; }
  table.track .c-appt .dbox, table.track .c-appt .visbtn { flex: 1 1 0; margin-top: 0; }
  table.track td.c-acts { display: flex; justify-content: flex-end; gap: 8px; }
  table.track .c-acts .btn { min-height: 40px; }
  table.track .c-tech .linkbtn { display: none; }   /* อยู่แถวปุ่มล่างแทน */
  .track-hint { display: none; }
  .trackpage > section.card { padding: 14px 10px; }
  table.track .linkbtn { min-height: 40px; font-size: 14px; }
  table.track .visbtn { min-height: 44px; }
  .trackpage .filters { order: 9; }
  .trackpage { display: flex; flex-direction: column; }
}

/* ── วิเคราะห์ ── */
.cols2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 980px) { .cols2 { grid-template-columns: minmax(0, 1fr); } }
.tile.red { background: var(--err-soft); color: #dc2626; }
details.model { border: 1px solid var(--line); border-radius: 12px; margin-top: 8px; background: #fff; }
details.model summary { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; padding: 11px 14px; cursor: pointer; list-style: none; }
details.model summary::-webkit-details-marker { display: none; }
details.model summary b { font-size: 15.5px; min-width: 110px; }
details.model summary .cnt { font-weight: 700; color: var(--pri-d); }
details.model[open] summary { border-bottom: 1px solid var(--line); background: var(--soft); border-radius: 12px 12px 0 0; }
details.model .tbl-wrap { padding: 4px 8px 8px; }
.cchips { display: flex; flex-wrap: wrap; gap: 4px; margin-left: auto; }
.cchip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; background: #fff7e6; color: #92400e; border: 1px solid #fde68a; }
.cchip b { font-weight: 700; }
table.list td.bad { color: #b91c1c; font-weight: 700; }
a.stat { text-decoration: none; color: inherit; }
a.stat:hover { border-color: var(--pri-2); }
table.months tr.on td { background: var(--pri-soft); }
table.months a { text-decoration: none; font-weight: 600; }

/* ── ทะเบียนช่าง ── */
.tech-form .fld { grid-template-columns: 150px minmax(0, 1fr); margin-bottom: 8px; }
.bl-form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 8px; margin: 4px 0 10px; }
@media (max-width: 760px) { .bl-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .tech-form .fld { grid-template-columns: minmax(0, 1fr); } }
.card-search { margin-left: auto; width: min(280px, 50%); }
.missing-techs { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* ── หน้าเคส: Blacklist / เช็กเบิก ── */
.todo.bad { background: linear-gradient(180deg, #fff6f6, #fef2f2); border-color: #fecaca; color: #991b1b; }
.todo.bad .todo-ic { color: #dc2626; }
.todo .chk-err { color: #b91c1c; font-weight: 600; margin-top: 4px; }
.todo .chk-warn { color: #92400e; margin-top: 4px; }
#blackBox, .sendstep > .todo, .paystep > .todo { max-width: none; }

/* ── หน้าเคส: ขั้นส่งช่าง ── */
.dispatch .disp-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 1100px) { .dispatch .disp-grid { grid-template-columns: minmax(0, 1fr); } }
.techpicks { display: grid; gap: 8px; margin-bottom: 12px; }
.techpick { display: grid; gap: 1px; text-align: left; font: inherit; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line-2); background: #fff; cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.techpick b { font-size: 15px; }
.techpick small { color: var(--mute); font-size: 12.5px; }
.techpick:hover { border-color: var(--pri-2); }
.techpick.on { border-color: var(--pri); box-shadow: 0 0 0 3px var(--pri-ring); background: #fafaff; }
.techinfo { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--mute); margin: -2px 0 10px; }
.hint-link { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; text-decoration: none; }
#d_msg { font-size: 14px; line-height: 1.6; background: #fbfbfe; }
.inline { display: flex; gap: 6px; align-items: center; }
.inline input { flex: 1; }
.dispatch .fld { grid-template-columns: 130px minmax(0, 1fr); }
@media (max-width: 640px) { .dispatch .fld { grid-template-columns: minmax(0, 1fr); } }
.causecard { width: 100%; max-width: 920px; margin: 0 auto; }
.chipbtn.pick { border-color: var(--line-2); color: var(--ink-2); }
.chipbtn.pick.on { background: #fff7e6; border-color: #f59e0b; color: #92400e; font-weight: 600; }
.fld.chk { grid-template-columns: 120px auto; justify-content: start; }
.fld.chk input { width: 20px; height: 20px; accent-color: var(--ok); }

/* ── หน้าต่างกลางจอ (รูปใบในแอปไลน์ / ล็อกอินใหม่) ── */
.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: rgba(15, 23, 42, .55); backdrop-filter: blur(2px); }
.modal-box { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: #fff; border-radius: 18px; padding: 18px; box-shadow: var(--shadow-lg); display: grid; gap: 10px; }
.modal-box h3 { margin: 0; font-size: 17px; }
.modal-box p { margin: 0; color: var(--ink-2); font-size: 14.5px; }
.modal-box img { width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; -webkit-touch-callout: default; user-select: auto; }
.modal-btns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.modal-btns .btn { min-height: 44px; text-decoration: none; }
.modal-login { display: grid; gap: 6px; }
.modal-login input { font-size: 16px; min-height: 44px; }
details.extra li .chipbtn { margin-left: 6px; }
