:root {
  --bg: #f3f5fa;
  --surface: #ffffff;
  --ink: #101828;
  --ink-soft: #344054;
  --muted: #667085;
  --line: #e6eaf2;
  --line-soft: #eef1f7;

  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #eaf0ff;
  --brand-ink: #1e40af;

  --ok: #067647;
  --ok-soft: #e7f6ee;
  --warn: #b54708;
  --warn-soft: #fdf3e4;
  --danger: #b42318;
  --danger-soft: #fdecea;

  --bar: #0f1729;
  --bar-2: #16233f;

  --r-sm: 8px;
  --r-md: 11px;
  --r-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 10px 28px -12px rgba(16, 24, 40, .16);
  --shadow-lg: 0 24px 60px -18px rgba(16, 24, 40, .32);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans Thai", "Noto Sans Thai", "Sarabun", "Leelawadee UI",
               "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); }

h1, h2, h3 { letter-spacing: -.01em; }

code {
  background: var(--line-soft); border: 1px solid var(--line); border-radius: 6px;
  padding: 1px 6px; font-size: 12.5px;
  font-family: "Cascadia Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
}

.wrap { max-width: 1140px; margin: 0 auto; padding: 0 22px; }
main.wrap { padding-top: 26px; padding-bottom: 72px; }

/* =========================================================
   หัวเว็บ + แถบเมนู
   ========================================================= */
.topbar {
  background: linear-gradient(135deg, #14203a, #1d4ed8);
  color: #fff;
  padding: 22px 0 26px;
}
.topbar .wrap {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: #fff; }
.brand .logo {
  width: 42px; height: 42px; border-radius: 12px;
  background: rgba(255, 255, 255, .16);
  border: 1px solid rgba(255, 255, 255, .1);
  display: grid; place-items: center; color: #fff;
}
.brand .logo svg { width: 25px; height: 25px; display: block; }
.brand-text h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: .2px; }
.brand-text p { margin: 0; font-size: 13px; opacity: .8; }

.navbar { background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: var(--shadow); }
.navbar .wrap { display: flex; gap: 4px; }
.navbar a {
  padding: 13px 18px; text-decoration: none; font-weight: 600; font-size: 14px;
  color: var(--muted); border-bottom: 3px solid transparent;
  transition: color .15s, border-color .15s;
}
.navbar a:hover { color: var(--ink); }
.navbar a.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---- เมนูบัญชี (dropdown) ---- */
.account { position: relative; }
.account-btn {
  display: flex; align-items: center; gap: 9px; cursor: pointer;
  background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 11px; padding: 5px 11px 5px 6px; color: #fff; font: inherit;
}
.account-btn:hover { background: rgba(255, 255, 255, .13); }
.account-btn .avatar {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(140deg, #3b82f6, #1d4ed8);
  display: grid; place-items: center; font-size: 14px; font-weight: 700;
}
.account-text { display: grid; line-height: 1.25; text-align: start; }
.account-text b { font-size: 13.5px; font-weight: 600; }
.account-text small { font-size: 11px; color: rgba(255, 255, 255, .55); }
.account-btn .caret {
  width: 0; height: 0; margin-inline-start: 2px;
  border-inline: 4px solid transparent; border-top: 5px solid rgba(255, 255, 255, .6);
}

.account-drop {
  position: absolute; inset-inline-end: 0; top: calc(100% + 8px); z-index: 50;
  min-width: 232px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 13px;
  box-shadow: var(--shadow-lg); padding: 6px; overflow: hidden;
}
.account-drop-head { padding: 10px 12px 12px; border-bottom: 1px solid var(--line-soft); margin-bottom: 6px; }
.account-drop-head b { display: block; font-size: 14px; }
.account-drop-head .who { color: var(--muted); font-size: 12.5px; margin-bottom: 7px; }
.account-drop a,
.account-drop button {
  display: block; width: 100%; text-align: start;
  padding: 9px 12px; border-radius: 9px; border: 0; background: transparent;
  font: inherit; font-size: 13.5px; font-weight: 500; color: var(--ink-soft);
  text-decoration: none; cursor: pointer;
}
.account-drop a:hover, .account-drop button:hover { background: var(--line-soft); color: var(--ink); }
.account-drop button.danger { color: var(--danger); }
.account-drop button.danger:hover { background: var(--danger-soft); }
.account-drop .sep { height: 1px; background: var(--line-soft); margin: 6px 4px; }

/* =========================================================
   หัวข้อหน้า / การ์ด / ฟอร์ม
   ========================================================= */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.page-head h2 { margin: 0; font-size: 21px; font-weight: 700; }
.page-head p { margin: 2px 0 0; font-size: 13.5px; }
.page-head a { text-decoration: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card > h2 { margin: 0 0 4px; font-size: 17px; }
.card > .hint { margin: 0 0 18px; color: var(--muted); font-size: 13.5px; }
.login-card { max-width: 396px; margin: 44px auto 0; padding: 28px; }
.form-card { max-width: 720px; }

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid.cols-3 { grid-template-columns: minmax(108px, .55fr) 1fr 1fr; }

label.field { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
input, select, textarea {
  width: 100%; margin-top: 6px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  font: inherit; font-size: 14.5px; color: var(--ink); background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
input:hover, select:hover { border-color: #cfd8ea; }
input:focus, select:focus, textarea:focus {
  outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
}
input[type="checkbox"] { width: auto; margin: 0; }
.hint-inline { display: block; margin-top: 5px; font-size: 12px; font-weight: 400; color: var(--muted); }
input[readonly] { background: #f6f7fb; color: var(--ink-soft); cursor: default; }
input[readonly]:hover, input[readonly]:focus { border-color: var(--line); box-shadow: none; }
.input-reveal { display: flex; gap: 8px; margin-top: 6px; }
.input-reveal input { margin-top: 0; font-family: "Cascadia Mono", ui-monospace, Consolas, monospace; }
.input-reveal button { flex: none; min-width: 76px; }
.input-reveal button:disabled { color: #b9c0cd; cursor: not-allowed; }
optgroup { font-size: 12.5px; color: var(--muted); }
optgroup option { color: var(--ink); font-size: 15px; }
label.check { display: flex; align-items: center; gap: 9px; margin-top: 16px; font-size: 13.5px; color: var(--ink-soft); }

button.primary {
  background: var(--brand); color: #fff; border: 0; border-radius: var(--r-md);
  padding: 11px 22px; font: inherit; font-size: 14.5px; font-weight: 600; cursor: pointer;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .1), 0 6px 14px -8px rgba(37, 99, 235, .8);
  transition: background .15s, transform .05s;
}
button.primary:hover { background: var(--brand-dark); }
button.primary:active { transform: translateY(1px); }
button.ghost {
  background: #fff; color: var(--ink-soft); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 9px 17px; font: inherit; font-size: 14px;
  font-weight: 600; cursor: pointer; transition: border-color .15s, background .15s;
}
button.ghost:hover { border-color: #cfd8ea; background: #fbfcfe; }
button.ghost.danger { color: var(--danger); }
button.ghost.danger:hover { border-color: #f0b3ad; background: var(--danger-soft); }
/* ปุ่มที่ถูกล็อกระหว่างส่งฟอร์ม — ต้องเห็นชัดว่ากดซ้ำไม่ได้แล้ว และ hover ต้องไม่เปลี่ยนสี */
button:disabled { cursor: not-allowed; opacity: .62; }
button.primary:disabled:hover { background: var(--brand); }
button.ghost:disabled:hover { border-color: var(--line); background: #fff; }
button.ghost.danger:disabled:hover { border-color: var(--line); background: #fff; }

.actions { display: flex; align-items: center; gap: 11px; flex-wrap: wrap; }
.actions a { text-decoration: none; }

/* =========================================================
   แจ้งเตือน / ป้ายสถานะ
   ========================================================= */
.alert {
  border-radius: var(--r-md); padding: 12px 15px; font-size: 14px; margin: 0 0 16px;
  border: 1px solid transparent;
}
.alert.error { background: var(--danger-soft); border-color: #f7d2ce; color: var(--danger); }
.alert.ok { background: var(--ok-soft); border-color: #bfe5d1; color: var(--ok); }
.alert.info { background: var(--brand-soft); border-color: #cfdcff; color: var(--brand-ink); font-size: 13px; }
.flash { position: sticky; top: 12px; z-index: 20; box-shadow: var(--shadow-sm); }

/* =========================================================
   แถบบอกสถานะกำลังโหลดหน้าใหม่
   วิ่งเข้าใกล้ 100% แล้วค้างไว้ ไม่วิ่งจนสุด เพราะไม่รู้ว่าหน้าใหม่จะมาถึงเมื่อไหร่
   ========================================================= */
.page-progress {
  position: fixed; inset-block-start: 0; inset-inline: 0; z-index: 100;
  height: 3px; overflow: hidden; pointer-events: none;
}
.page-progress::before {
  content: ''; display: block; height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--brand), #60a5fa);
  box-shadow: 0 0 8px rgba(37, 99, 235, .55);
  transform-origin: 0 50%;
  animation: page-progress-run 12s cubic-bezier(.1, .65, .2, 1) forwards;
}
@keyframes page-progress-run {
  0%   { transform: scaleX(.03); }
  30%  { transform: scaleX(.5); }
  70%  { transform: scaleX(.82); }
  100% { transform: scaleX(.97); }
}
/* ผู้ใช้ที่ตั้งค่าลดการเคลื่อนไหว — โชว์เป็นแถบนิ่งพอให้รู้ว่ากำลังทำงาน */
@media (prefers-reduced-motion: reduce) {
  .page-progress::before { animation: none; transform: scaleX(1); opacity: .45; }
}

/* ---- กล่องกลางจอ ---- */
.page-loader {
  /* ล้างกรอบและกล่องขาวที่เบราว์เซอร์ใส่ให้ dialog มา เหลือแต่การ์ดข้างใน */
  border: 0; padding: 0; background: transparent;
  max-width: none; max-height: none; overflow: visible;
  margin: auto;   /* จัดกลางจอทั้งแนวตั้งและแนวนอน */
}
.page-loader::backdrop { background: rgba(12, 20, 38, .45); backdrop-filter: blur(2px); }

.page-loader-box {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 26px 36px; border-radius: var(--r-lg);
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-lg);
  font-size: 14.5px; font-weight: 600;
}

.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--brand);
  animation: spinner-turn .75s linear infinite;
}
@keyframes spinner-turn { to { transform: rotate(360deg); } }

/* หมุนช้าลงมากแทนการหยุดนิ่ง ไม่งั้นจะดูเหมือนค้าง */
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.6s; }
}
.err { color: var(--danger); font-size: 12.5px; margin-top: 5px; display: block; }
input.is-invalid, select.is-invalid { border-color: #e8a49c; }
input.is-invalid:focus, select.is-invalid:focus { box-shadow: 0 0 0 3px rgba(180, 35, 24, .12); }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.role-sa { background: #fdf0dc; color: var(--warn); }
.badge.role-admin { background: var(--brand-soft); color: var(--brand-ink); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.off { background: var(--line-soft); color: var(--muted); }
.account-drop-head .badge.role-admin { background: var(--brand-soft); }

/* =========================================================
   ตาราง
   ========================================================= */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: start; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th {
  font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .3px;
  background: #fafbfd; border-bottom-color: var(--line);
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfe; }
td .sub, td.sub { color: var(--muted); font-size: 12.5px; }
.table-scroll { overflow-x: auto; }
.empty { text-align: center; color: var(--muted); padding: 44px 10px; }
.muted { color: var(--muted); }
.right { text-align: end; }

/* ---- แบ่งหน้า ---- */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; padding: 13px 16px; background: #fafbfd;
  border-top: 1px solid var(--line);
}
.pagination-info { font-size: 13px; color: var(--muted); }
.pagination-links { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.pagination .page {
  min-width: 34px; height: 34px; padding: 0 11px;
  display: inline-grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff;
  font-size: 13.5px; font-weight: 600; color: var(--ink-soft); text-decoration: none;
}
.pagination a.page:hover { border-color: var(--brand); color: var(--brand); }
.pagination .page.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.pagination .page.disabled { color: #b9c0cd; background: #f7f8fb; }
.pagination .page.gap { border-color: transparent; background: transparent; color: var(--muted); }

/* =========================================================
   รายงาน
   ========================================================= */
.filters { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.filters label.field { flex: 1 1 190px; min-width: 170px; }
.filters button { flex: none; }

.quick-ranges {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  margin-top: 16px; padding-top: 15px; border-top: 1px solid var(--line-soft); font-size: 13px;
}
.chip-link {
  text-decoration: none; border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 14px; font-size: 13px; font-weight: 600; color: var(--ink-soft); background: #fff;
}
.chip-link:hover { border-color: var(--brand); color: var(--brand); }
.chip-link.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.range-note { margin: 0 0 16px; font-size: 13.5px; color: var(--muted); }
.range-note b { color: var(--ink); }

.stats { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.stat .l { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat .n { font-size: 27px; font-weight: 700; line-height: 1.25; letter-spacing: -.02em; color: var(--brand-ink); }
.stat .n.small { font-size: 18px; padding: 4px 0; }
.stat .s { color: var(--muted); font-size: 12px; }

/* =========================================================
   ปฏิทิน
   ========================================================= */
.calendar-layout { display: grid; grid-template-columns: 1fr 306px; gap: 18px; align-items: start; }
.calendar-card { padding: 16px; }

.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.cal-title { font-size: 17px; font-weight: 700; min-width: 172px; text-align: center; }
.cal-nav {
  width: 32px; height: 32px; border-radius: var(--r-sm); border: 1px solid var(--line);
  display: grid; place-items: center; text-decoration: none; color: var(--ink-soft);
  font-size: 20px; line-height: 1;
}
.cal-nav:hover { border-color: var(--brand); color: var(--brand); }
.cal-today {
  margin-inline-start: auto; text-decoration: none; font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); border-radius: var(--r-sm); padding: 6px 15px; color: var(--ink-soft);
}
.cal-today:hover { border-color: var(--brand); color: var(--brand); }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-weekday { text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); padding: 2px 0 8px; }
.cal-weekday .wd-short { display: none; }
.cal-weekday.weekend { color: #b04a5e; }

.cal-day {
  min-height: 94px; border: 1px solid var(--line); border-radius: var(--r-md); background: #fff;
  padding: 7px; font: inherit; text-align: start; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px; overflow: hidden;
  transition: border-color .12s, background .12s;
}
.cal-day:hover { border-color: #cfd8ea; background: #fafbfe; }
.cal-day .d { font-size: 13px; font-weight: 700; color: var(--ink); }
.cal-day.outside { background: #fafbfd; }
.cal-day.outside .d { color: #bcc3d0; font-weight: 500; }
.cal-day.today .d {
  background: var(--brand); color: #fff; border-radius: 50%;
  width: 23px; height: 23px; display: grid; place-items: center; font-size: 12px;
}
.cal-day.selected { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.cal-day .chip {
  background: var(--brand-soft); color: var(--brand-ink); border-radius: 6px;
  padding: 2px 7px; font-size: 11.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-day .more { font-size: 11px; color: var(--muted); padding-inline-start: 4px; }

.day-panel { position: sticky; top: 14px; }
.day-panel h3 { margin: 0 0 2px; font-size: 15.5px; }
.day-panel > .muted { margin: 0 0 14px; font-size: 13px; }
.day-item {
  border-inline-start: 3px solid var(--brand); background: #fafbfd;
  border-radius: 0 var(--r-md) var(--r-md) 0; padding: 9px 13px; margin-bottom: 9px;
}
.day-item b { color: var(--brand-ink); font-size: 13.5px; }
.day-item .sub { color: var(--muted); font-size: 12px; }

/* =========================================================
   Modal เพิ่มนัดหมาย
   ========================================================= */
dialog.modal {
  border: 0; border-radius: var(--r-lg); padding: 0;
  width: min(730px, calc(100vw - 32px));
  box-shadow: var(--shadow-lg); color: var(--ink);
}
dialog.modal::backdrop { background: rgba(12, 20, 38, .48); backdrop-filter: blur(2px); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 17px 22px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 16.5px; }
.modal-close {
  border: 0; background: transparent; font-size: 24px; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 0 4px; border-radius: 6px;
}
.modal-close:hover { color: var(--ink); background: var(--line-soft); }
.modal-body { padding: 22px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 11px; flex-wrap: wrap;
  padding: 16px 22px; border-top: 1px solid var(--line); background: #fafbfd;
}

/* =========================================================
   หน้าแจ้งข้อผิดพลาด
   ========================================================= */
/* ปุ่มที่ต้องอยู่ซ้ายสุดของแถบปุ่มท้าย modal (เช่น "ล้างสถานะนี้") */
.modal-foot-start { margin-inline-end: auto; }
.modal-foot-start[hidden] { display: none; }

.error-page { max-width: 540px; padding-top: 72px; text-align: center; }
.error-page .card { padding: 36px 28px; }
.error-page h2 { margin: 0 0 6px; font-size: 20px; }
.error-page .hint { margin: 0 0 20px; }
.error-code {
  font-size: 46px; font-weight: 800; letter-spacing: -.02em;
  color: var(--brand); line-height: 1.1; margin-bottom: 4px;
}
.error-page a { text-decoration: none; }

/* =========================================================
   จอเล็ก
   ========================================================= */
@media (max-width: 900px) {
  .calendar-layout { grid-template-columns: 1fr; }
  .day-panel { position: static; }
  .cal-day { min-height: 70px; }
  .cal-day .chip { font-size: 10.5px; }
}

@media (max-width: 760px) {
  .topbar { padding: 16px 0 18px; }
  .navbar .wrap { overflow-x: auto; }
  .navbar a { white-space: nowrap; padding-inline: 13px; }
  .account-text { display: none; }
  .grid.cols-3 { grid-template-columns: 1fr; }
  .day-panel { top: 12px; }
}

/* =========================================================
   ปุ่มสลับยี่ห้อรถ (ในเมนูบัญชี)
   ========================================================= */
.brand-switch { padding: 4px 12px 10px; border-bottom: 1px solid var(--line-soft); margin-bottom: 6px; }
.brand-switch-head {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600; color: var(--muted);
  letter-spacing: .3px; margin-bottom: 7px;
}
.brand-switch-list { display: flex; flex-wrap: wrap; gap: 6px; }
.brand-switch-list form { display: contents; }
.account-drop .brand-switch-btn {
  display: inline-block; width: auto; padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  font: inherit; font-size: 12.5px; font-weight: 600; color: var(--ink-soft);
  cursor: pointer; white-space: nowrap;
}
.account-drop .brand-switch-btn:hover { background: var(--line-soft); color: var(--ink); }
.account-drop .brand-switch-btn.active {
  background: var(--brand); border-color: var(--brand); color: #fff;
}
.account-drop .brand-switch-btn.active:hover { background: var(--brand-dark); color: #fff; }
.account-drop .brand-switch-reset {
  display: inline-block; width: auto; margin-top: 8px; padding: 4px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: transparent;
  font: inherit; font-size: 12px; font-weight: 500; color: var(--muted); cursor: pointer;
}
.account-drop .brand-switch-reset:hover { background: var(--line-soft); color: var(--ink-soft); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* ช่องติ๊กยี่ห้อในฟอร์มผู้ใช้ */
.brand-picker { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 4px; }
.brand-picker .check { margin-top: 0; }

/* เลขตัวถัง VIN — ตัวอักษรความกว้างเท่ากัน อ่าน/เทียบทีละหลักได้ง่าย */
code.vin { font-size: 12px; letter-spacing: .4px; padding: 2px 6px; white-space: nowrap; }
.vin-input { font-family: "Cascadia Mono", ui-monospace, "SFMono-Regular", Consolas, monospace; letter-spacing: .5px; text-transform: uppercase; }

/* =========================================================
   รายการต้องโทรหาลูกค้า
   ========================================================= */
tr.row-overdue td { background: #fffaf5; }
tr.row-overdue td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.overdue-note { color: var(--warn); }
.no-phone { color: var(--danger); }
.source-missing { color: var(--warn); font-weight: 600; }
.phone-bad { color: var(--warn); text-decoration: underline dotted; }
.phone-warn { color: var(--warn); font-size: 12px; margin-inline-start: 2px; }

/* =========================================================
   แถบเครื่องมือหัวหน้า + ช่องค้นหา
   ========================================================= */

/* กลุ่มปุ่ม/ช่องค้นหาที่อยู่ขวาสุดของหัวข้อหน้า */
.page-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.search-box { display: flex; align-items: center; gap: 8px; }

.search-field { position: relative; width: 230px; }
.search-field input {
  /* ชิดกับปุ่มข้าง ๆ จึงไม่เอา margin-top ของ input ทั่วไป และเว้นที่ให้ไอคอนสองข้าง */
  margin-top: 0; padding: 8px 30px 8px 34px; font-size: 13.5px;
  background: var(--surface);
}
.search-field input::placeholder { color: #98a2b3; }

.search-icon {
  position: absolute; inset-inline-start: 11px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--muted); pointer-events: none;
}
.search-icon svg { width: 100%; height: 100%; display: block; }

.search-clear {
  position: absolute; inset-inline-end: 6px; top: 50%; transform: translateY(-50%);
  width: 19px; height: 19px; border-radius: 50%;
  display: grid; place-items: center; text-decoration: none;
  font-size: 15px; line-height: 1; color: var(--muted); background: var(--line-soft);
}
.search-clear:hover { background: var(--line); color: var(--ink); }

.search-go { flex: none; padding: 8px 14px; font-size: 13.5px; }

/* จอแคบ — ให้แถบเครื่องมือลงมาเต็มบรรทัดแล้วช่องค้นหายืดเอง */
@media (max-width: 760px) {
  .page-tools { width: 100%; justify-content: stretch; }
  .search-box { flex: 1 1 100%; }
  .search-field { flex: 1 1 auto; width: auto; }
}

/* สถานะคิวเช็คระยะ */
/* ยังไม่ได้ลงมือ = สีหลัก · โทรไม่ติด = เหลืองเตือน · นัดเรียบร้อย = เขียว · เลยกำหนดยังไม่ปิดงาน = แดง */
.badge.status-waiting     { background: var(--brand-soft); color: var(--brand-ink); }
.badge.status-unreachable { background: var(--warn-soft); color: var(--warn); }
.badge.status-booked      { background: var(--ok-soft); color: var(--ok); }
.badge.status-overdue     { background: var(--danger-soft); color: var(--danger); }
/* งานที่ปิดไปแล้วเป็นของจบแล้ว ใช้สีกลาง ๆ ให้เขียวเหลือความหมายเดียวคือ "ยืนยันนัดหมาย" */
.badge.status-done        { background: var(--line-soft); color: var(--muted); }
/* บรรทัดบอกว่าคิวนี้ถูกเลื่อนวันโทรมา — สีเดียวกับคำเตือนอื่นในตาราง */
.recall-note { color: var(--warn); }
.model-name { font-size: 13.5px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.row-actions form { display: contents; }

/* =========================================================
   แถบกรองสถานะ (หน้ารายการนัดหมาย)
   ========================================================= */
.status-bar {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  padding: 11px 16px; background: #fafbfd; border-bottom: 1px solid var(--line);
}
.status-bar .chip-link { display: inline-flex; align-items: center; gap: 6px; }
/* ตัวเลขจำนวนในชิป — จาง ๆ กว่าชื่อสถานะ ไม่ให้แย่งสายตา */
.chip-count { font-weight: 700; font-size: 12px; color: var(--muted); }
.chip-link:hover .chip-count { color: var(--brand); }
.chip-link.active .chip-count { color: rgba(255, 255, 255, .8); }

/* จอใหญ่ใช้ชิป เห็นทุกสถานะพร้อมจำนวนในตาเดียว — dropdown โผล่เฉพาะจอแคบ (ดูท้ายไฟล์) */
.status-jump { display: none; }

/* =========================================================
   แถบเลือกเดือน + หัวกลุ่มในตาราง (หน้าต้องโทรหา)
   ========================================================= */
.month-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 11px 16px; background: #fafbfd; border-bottom: 1px solid var(--line);
}
.month-title { font-size: 15px; font-weight: 700; color: var(--ink); }

/* ช่องกระโดดข้ามเดือน — select ทั่วไปกว้าง 100% ตรงนี้ต้องพอดีข้อความ */
.month-jump { display: flex; align-items: center; gap: 6px; }
.month-jump select {
  width: auto; margin-top: 0; padding: 7px 10px;
  font-size: 14.5px; font-weight: 700; color: var(--ink); cursor: pointer;
}
.month-jump select:hover { border-color: #cfd8ea; }
/* ปุ่มสลับมุมมองไปชิดขวาสุด แยกออกจากกลุ่มปุ่มเลื่อนเดือน */
.month-bar .month-switch { margin-inline-start: auto; }

/* หัวกลุ่มคั่นระหว่าง "คิวค้างเก่า" กับ "คิวของเดือนที่เลือก" */
tr.group-row td {
  padding: 8px 16px; background: var(--line-soft);
  font-size: 12px; font-weight: 700; letter-spacing: .3px; color: var(--muted);
  border-bottom: 1px solid var(--line);
}
tr.group-row:hover td { background: var(--line-soft); }
tr.group-row td.group-overdue { background: var(--warn-soft); color: var(--warn); }
tr.group-row:hover td.group-overdue { background: var(--warn-soft); }
/* =========================================================
   จอแท็บเล็ต/มือถือ — กันเบราว์เซอร์ซูมเอง
   ========================================================= */
@media (max-width: 760px) {
  /* Safari บน iOS จะซูมหน้าจอทุกครั้งที่โฟกัสช่องที่ตัวอักษรเล็กกว่า 16px */
  input, select, textarea,
  .search-field input,
  optgroup option { font-size: 16px; }
}

/* =========================================================
   จอมือถือ (≤ 560px)
   ========================================================= */
@media (max-width: 560px) {
  /* คืนพื้นที่ขอบจอให้เนื้อหา */
  .wrap { padding: 0 14px; }
  main.wrap { padding-top: 18px; padding-bottom: 48px; }
  .page-head h2 { font-size: 19px; }
  .card { padding: 16px; }
  .modal-body { padding: 16px; }
  .modal-head, .modal-foot { padding-inline: 16px; }

  /* ปุ่มหลักของหัวข้อหน้าเต็มบรรทัด กดง่ายกว่าปุ่มลอยชิดขวา */
  .page-head > button.primary,
  .page-head > a,
  .page-head > a > button.primary { width: 100%; }
  .page-tools > button.primary { flex: 1 1 100%; }

  /* ---- หัวปฏิทิน: เลิกตรึงความกว้างขั้นต่ำ ไม่งั้นดันจนหน้าเลื่อนซ้ายขวาได้ ---- */
  .cal-head { gap: 6px; }
  .cal-title { min-width: 0; flex: 1 1 auto; font-size: 15.5px; }
  .cal-today { flex: none; padding: 6px 12px; }

  /* ---- ช่องปฏิทิน: ใช้ชื่อวันย่อ และสรุปเป็นจำนวนนัดแทนรายชื่อ (ช่องแคบเกินกว่าจะอ่านชื่อได้) ---- */
  .cal-weekday { font-size: 11.5px; padding-bottom: 6px; }
  .cal-weekday .wd-full { display: none; }
  .cal-weekday .wd-short { display: inline; }

  .cal-grid { gap: 4px; }
  .cal-day { min-height: 56px; padding: 5px 4px; border-radius: var(--r-sm); }
  .cal-day .d { font-size: 12.5px; }
  .cal-day.today .d { width: 21px; height: 21px; font-size: 11.5px; }
  .cal-day .chip, .cal-day .more { display: none; }
  .cal-day.has-events::after {
    content: attr(data-count);
    margin-top: auto; align-self: flex-start;
    min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
    background: var(--brand-soft); color: var(--brand-ink);
    font-size: 10.5px; font-weight: 700;
    display: grid; place-items: center;
  }

  /* ---- แถบเลือกเดือน: ชื่อเดือนยืดเต็มที่เหลือ ปุ่มสลับมุมมองลงบรรทัดใหม่ ---- */
  /* ---- แถบกรองสถานะ: ชิป 7 อันกว้างเกินจอมือถือ สลับไปใช้ dropdown แทน ---- */
  .status-bar { display: none; }
  .status-jump {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px; background: #fafbfd; border-bottom: 1px solid var(--line);
  }
  .status-jump-label { flex: none; font-size: 12.5px; font-weight: 600; color: var(--muted); }
  .status-jump select {
    flex: 1 1 auto; min-width: 0; /* เป็น flex item ต้องยอมหดตามช่องที่เหลือ ไม่งั้นดันป้ายตก */
    margin-top: 0; padding: 8px 10px; font-size: 16px; font-weight: 600;
  }

  .month-bar { padding: 10px 14px; gap: 6px; }
  .month-title { flex: 1 1 auto; text-align: center; font-size: 14.5px; }
  .month-jump { flex: 1 1 auto; }
  .month-jump select { width: 100%; font-size: 16px; text-align: center; }
  .month-bar .month-switch { flex: 1 1 100%; margin-inline-start: 0; text-align: center; }
  tr.group-row td { padding-inline: 14px; }

  /* ---- ขยายเป้ากดให้พอดีนิ้ว ---- */
  .cal-nav { width: 38px; height: 38px; }
  .pagination .page { min-width: 40px; height: 40px; }
  .row-actions { gap: 8px; }
}
