:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #f59e0b;
  --brand-dark: #b45309;
  --primary: #0f172a;
  --danger: #b91c1c;
  --radius: 12px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Sarabun", "Leelawadee UI", "Noto Sans Thai", Tahoma, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* ---------- ฟอร์มและปุ่ม ---------- */
label { display: block; font-size: .9rem; font-weight: 600; margin-bottom: 4px; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #fff;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}
.field { margin-bottom: 12px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.brand { background: var(--brand); border-color: var(--brand); color: #1c1917; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; padding: 6px 12px; font-size: .9rem; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--c) 14%, #fff);
  color: var(--c);
  font-size: .8rem;
  font-weight: 700;
  white-space: nowrap;
}
.error { color: var(--danger); font-size: .9rem; min-height: 1.4em; margin: 6px 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }

/* ---------- หน้าลูกค้า ---------- */
.public-header { background: var(--primary); color: #fff; padding: 18px 16px; }
.public-header .inner, .public-main { max-width: 560px; margin: 0 auto; }
.public-header p { margin: 4px 0 0; color: #cbd5e1; font-size: .9rem; }
.public-main { padding: 16px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #e2e8f0; padding: 4px; border-radius: 12px; margin-bottom: 16px; }
.tabs button { min-height: 42px; border: 0; border-radius: 9px; background: transparent; font-weight: 700; cursor: pointer; }
.tabs button.active { background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.step-title { margin: 18px 0 8px; font-size: 1rem; }
.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.choice {
  min-height: 56px; padding: 6px; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff;
  cursor: pointer; text-align: center; font-weight: 600; line-height: 1.3;
}
.choice small { display: block; font-weight: 400; color: var(--muted); }
.choice.active { border-color: var(--brand-dark); background: #fffbeb; box-shadow: inset 0 0 0 1px var(--brand-dark); }
.choice:disabled { opacity: .45; cursor: not-allowed; }
.confirm { text-align: center; }
.confirm .job-no { font-size: 1.6rem; font-weight: 800; letter-spacing: .04em; margin: 8px 0; }
.timeline { list-style: none; margin: 12px 0 0; padding: 0; }
.timeline li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); font-size: .92rem; }
.footer-link { text-align: center; margin: 24px 0; font-size: .85rem; }

/* ---------- หน้าพนักงาน ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px; background: var(--primary); color: #fff;
}
.topbar h1 { font-size: 1.05rem; margin-right: auto; }
.topbar select { width: auto; min-height: 38px; padding: 4px 8px; color: var(--text); }
.topbar .btn { min-height: 38px; padding: 4px 12px; color: var(--text); }
.nav { display: flex; gap: 4px; padding: 8px 12px 0; overflow-x: auto; background: #fff; border-bottom: 1px solid var(--line); }
.nav button {
  min-height: 42px; padding: 6px 14px; border: 0; border-bottom: 3px solid transparent;
  background: none; font-weight: 700; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.nav button.active { color: var(--text); border-bottom-color: var(--brand); }
.page { padding: 12px; max-width: 1500px; margin: 0 auto; }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar input { flex: 1; }

.status-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 4px; }
.status-tabs button {
  flex: none; min-height: 44px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: #fff; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.status-tabs button b { margin-left: 4px; color: var(--c); }
.status-tabs button.active { background: var(--c); border-color: var(--c); color: #fff; }
.status-tabs button.active b { color: #fff; }

.board { display: block; }
.column { display: none; }
.column.active { display: block; }
.column > header { display: none; }
.empty { padding: 28px 8px; text-align: center; color: var(--muted); }

.job {
  background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--c, #94a3b8);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer;
}
.job .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.job .model { font-weight: 700; }
.job .plate { font-weight: 600; }
.job .meta { color: var(--muted); font-size: .86rem; margin-top: 2px; overflow-wrap: anywhere; }
.job .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.age { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.age.late { color: var(--danger); font-weight: 700; }

.day-strip { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; }
.day-strip button {
  flex: none; min-width: 78px; min-height: 58px; padding: 4px 8px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; cursor: pointer; line-height: 1.3; font-weight: 600;
}
.day-strip button small { display: block; font-weight: 400; color: var(--muted); }
.day-strip button.active { border-color: var(--brand-dark); background: #fffbeb; }
.day-strip button.full small { color: var(--danger); font-weight: 700; }

dialog {
  width: min(640px, 100%); max-width: 100%; max-height: 100dvh; margin: auto;
  padding: 0; border: 0; border-radius: 14px; color: var(--text);
}
dialog::backdrop { background: rgb(15 23 42 / .55); }
dialog .head {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px; background: #fff; border-bottom: 1px solid var(--line);
}
dialog .body { padding: 16px; }
dialog .foot {
  position: sticky; bottom: 0; display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 16px; background: #fff; border-top: 1px solid var(--line);
}
.section-title { margin: 18px 0 8px; padding-top: 12px; border-top: 1px solid var(--line); font-size: .95rem; color: var(--muted); }
.radio-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }

.login-wrap { max-width: 380px; margin: 12vh auto 0; padding: 16px; }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px; background: #0f172a; color: #fff;
}
.toast.bad { background: var(--danger); }

@media (max-width: 640px) {
  dialog { width: 100%; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  dialog form { min-height: 100dvh; display: flex; flex-direction: column; }
  dialog .body { flex: 1; }
}

/* จอกว้าง: แสดง 6 คอลัมน์พร้อมกันเหมือนตารางรถเข้าซ่อม */
@media (min-width: 1100px) {
  .status-tabs { display: none; }
  .board { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; align-items: start; }
  .column, .column.active { display: block; background: #e8edf3; border-radius: var(--radius); padding: 8px; }
  .column > header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 4px 6px 8px; font-weight: 700; color: var(--c);
  }
  .column > header b { background: #fff; border-radius: 999px; padding: 0 9px; }
  .job .actions .btn { flex: 1; }
}

/* ---------- บริการ ราคา และปฏิทินนัด ---------- */
.row.three { grid-template-columns: repeat(3, 1fr); }
.row.name { grid-template-columns: 110px 1fr; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.check {
  display: flex; align-items: center; gap: 8px; min-height: 44px; margin: 0; padding: 6px 10px;
  border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; font-weight: 500; cursor: pointer;
}
.check input { width: 20px; min-height: 20px; height: 20px; flex: none; accent-color: var(--brand-dark); }
.check:has(input:checked) { border-color: var(--brand-dark); background: #fffbeb; }

.quote { list-style: none; margin: 12px 0 4px; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; }
.quote > li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; border-top: 1px solid var(--line); }
.quote > li:first-child { border-top: 0; }
.quote .detail { display: block; padding-top: 0; border-top: 0; }
.quote .detail ul { list-style: none; margin: 0; padding: 0 0 0 12px; color: var(--muted); font-size: .86rem; }
.quote .detail li { display: flex; justify-content: space-between; gap: 12px; }
.quote .total { font-weight: 700; background: #fffbeb; border-radius: 0 0 10px 10px; }

.job .service { font-size: .9rem; color: #334155; margin-top: 2px; }
.toolbar { flex-wrap: wrap; }
.link { border: 0; background: none; padding: 4px 0; color: var(--muted); font-size: .8rem; text-decoration: underline; cursor: pointer; }
.full { color: var(--danger); font-weight: 700; }

.week { display: block; }
.day { display: none; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.day.active { display: block; }
.day > header { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 10px; background: #fde68a; }
.day.today > header { background: var(--brand); }
.day .closed { margin: 0; padding: 40px 8px; text-align: center; color: var(--danger); font-size: 1.4rem; font-weight: 700; }
.day .closed small { display: block; font-size: .85rem; font-weight: 400; color: var(--muted); }
.slot { border-top: 2px solid #94a3b8; }
.slot .time { padding: 3px 10px; background: #fef9c3; font-weight: 700; font-size: .9rem; }
.lane { padding: 4px 6px 6px; min-height: 44px; }
.lane-check { background: #fdece2; }
.lane-head { display: flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--muted); }
.lane-head > span:first-child { margin-right: auto; font-weight: 700; }
.lane-head .add {
  width: 30px; height: 30px; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff;
  font-size: 1.1rem; line-height: 1; cursor: pointer;
}
.entry {
  display: block; width: 100%; margin-top: 4px; padding: 5px 8px; border: 0; border-left: 4px solid var(--c);
  border-radius: 6px; background: #fff; box-shadow: 0 0 0 1px var(--line); text-align: left; font-size: .86rem;
  font-weight: 700; cursor: pointer; overflow-wrap: anywhere;
}
.entry span { font-weight: 400; }
.entry.cont { opacity: .6; font-weight: 400; }

.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 12px; }
.summary div { display: flex; flex-direction: column; }
.summary b { font-size: 1.1rem; }

@media (min-width: 1100px) {
  #day-strip { display: none; }
  .week { display: grid; grid-template-columns: repeat(var(--n, 6), minmax(0, 1fr)); gap: 6px; align-items: start; }
  .day, .day.active { display: block; }
}

/* ---------- งานหน้างาน: เช็คลิสต์ ปัญหา รูปถ่าย ---------- */
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; background: #f1f5f9; color: #334155; font-size: .78rem; font-weight: 600; }
.chip.late { background: #fee2e2; color: var(--danger); }
.work-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.progress { height: 8px; margin: 8px 0 2px; border-radius: 999px; background: #e2e8f0; overflow: hidden; }
.progress span { display: block; height: 100%; background: #16a34a; }
.work { display: grid; gap: 6px; }
.work-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; }
.checklist, .issues { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--line); }
.checklist label { flex: 1; display: flex; align-items: center; gap: 10px; min-height: 48px; margin: 0; font-weight: 500; cursor: pointer; }
.checklist input { width: 24px; height: 24px; min-height: 24px; flex: none; accent-color: #16a34a; }
.checklist li.done span { color: var(--muted); text-decoration: line-through; }
.checklist small, .issues small, .photos figcaption { display: block; font-size: .75rem; color: var(--muted); text-decoration: none; }
.issues li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; margin-bottom: 6px;
  border-radius: 8px; background: #fef2f2; border-left: 4px solid var(--danger); }
.issues li.resolved { background: #f8fafc; border-left-color: #94a3b8; color: var(--muted); }
.inline-form { display: flex; gap: 6px; }
.inline-form input { flex: 1; }
.icon-btn { flex: none; width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 1.2rem; cursor: pointer; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.photos figure { position: relative; margin: 0; }
.photos img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: #e2e8f0; }
.photos figure .icon-btn { position: absolute; top: 2px; right: 2px; background: rgb(255 255 255 / .85); }
.photo-add { display: flex; align-items: center; justify-content: center; aspect-ratio: 1; margin: 0; border: 2px dashed #cbd5e1;
  border-radius: 8px; background: #fff; color: var(--muted); text-align: center; font-size: .85rem; cursor: pointer; }
.tech-who { display: grid; gap: 6px; margin-bottom: 8px; }
.tech-who select { font-size: 1.05rem; }
.tech-card .top { align-items: center; }
.tech-card { cursor: default; }
.tech-work { margin-top: 10px; padding-top: 6px; border-top: 1px dashed var(--line); }

/* ---------- ไทม์ไลน์ ---------- */
.scope-select, #timeline-filter { width: auto; flex: none; }
.tl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; margin-bottom: 8px; }
.tl { --label: 190px; --day: 34px; min-width: calc(var(--label) + var(--days) * var(--day)); }
.tl-row { position: relative; display: grid; grid-template-columns: var(--label) repeat(var(--days), var(--day)); align-items: stretch; border-bottom: 1px solid var(--line); min-height: 52px; cursor: pointer; }
.tl-row:hover { background: #f8fafc; }
.tl-head { min-height: 40px; cursor: default; position: sticky; top: 0; z-index: 2; background: #fff; }
.tl-label { position: sticky; left: 0; z-index: 1; grid-row: 1; grid-column: 1; padding: 6px 8px; background: inherit; background-color: #fff;
  border-right: 1px solid var(--line); font-size: .85rem; line-height: 1.3; overflow: hidden; }
.tl-label small { display: block; color: var(--muted); font-size: .75rem; }
.tl-label em { color: var(--danger); font-style: normal; font-weight: 700; }
.tl-day { grid-row: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: .7rem; color: var(--muted); border-left: 1px solid #f1f5f9; }
.tl-day b { font-size: .85rem; color: var(--text); }
.tl-day.today { background: #fef3c7; }
.tl-cell { grid-row: 1; border-left: 1px solid #f1f5f9; }
.tl-cell.today { background: #fffbeb; }
.tl-bar { grid-row: 1; align-self: center; z-index: 1; height: 26px; margin: 0 2px; padding: 0 6px; display: flex; align-items: center;
  border-radius: 6px; background: color-mix(in srgb, var(--c) 22%, #fff); border: 2px solid var(--c); overflow: hidden; }
.tl-bar span { font-size: .72rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.tl-bar.open { border-right-style: dashed; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.tl-bar.late { border-color: var(--danger); background: #fee2e2; }

/* ---------- ภาพรวม ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.tile { display: flex; flex-direction: column; padding: 12px 14px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.tile span { font-size: .85rem; color: var(--muted); }
.tile b { font-size: 1.6rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile small { color: var(--muted); font-size: .8rem; }
.tile.alert { border-color: #fecaca; background: #fef2f2; }
.tile.alert b { color: var(--danger); }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; margin-bottom: 12px; }
.dash-grid .card h2, .due h2 { margin-bottom: 4px; font-size: 1rem; }
.bars { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.bars li { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; align-items: center; gap: 8px; font-size: .88rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 12px; border-radius: 0 4px 4px 0; background: #f1f5f9; }
.bar-fill { display: block; height: 100%; border-radius: 0 4px 4px 0; background: #0f766e; }
.bar-value { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.cols { display: flex; align-items: flex-end; gap: 4px; height: 160px; margin-top: 10px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.col { position: relative; flex: 1; height: 100%; display: flex; align-items: flex-end; cursor: default; }
.col:hover .col-fill, .col:focus .col-fill { background: #115e59; }
.col-fill { display: block; width: 100%; border-radius: 4px 4px 0 0; background: #0f766e; }
.col-x { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: .7rem; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.mini-table { width: 100%; border-collapse: collapse; font-size: .85rem; margin-top: 6px; }
.mini-table th, .mini-table td { padding: 5px 6px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; font-variant-numeric: tabular-nums; }
.mini-table th { color: var(--muted); font-weight: 600; }
.dash-grid .issues li { cursor: pointer; }
.due-list { list-style: none; margin: 8px 0 0; padding: 0; }
.due-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.due-list small { display: block; color: var(--muted); font-size: .8rem; }
.due-list .late-text { color: var(--danger); font-weight: 700; }
.due-list li.overdue { background: linear-gradient(90deg, #fef2f2, transparent); }
.due-actions { display: flex; gap: 6px; }
@media (max-width: 640px) { .tl { --label: 140px; --day: 30px; } }
