/* กิ้มเส็ง ค้าข้าว — CRM styling.
   Palette ported from the source design (oklch). */
:root {
  --app-bg:      oklch(0.965 0.008 255);
  --card-bg:     oklch(1 0 0);
  --text:        oklch(0.20 0.02 260);
  --text-2:      oklch(0.30 0.02 260);
  --muted:       oklch(0.48 0.02 255);
  --border:      oklch(0.88 0.012 255);
  --border-row:  oklch(0.90 0.012 255);
  --input-bg:    oklch(0.965 0.008 255);
  --input-border:oklch(0.82 0.02 255);
  --btn-border:  oklch(0.78 0.02 255);
  --primary:     oklch(0.62 0.16 255);
  --on-primary:  oklch(1 0 0);
  --danger:      oklch(0.62 0.19 25);
  --row-hover:   oklch(0.95 0.012 255);
  /* พื้นอ่อนสำหรับไฮไลต์อ่อน ๆ (โทนตามธีมเดิม) */
  --primary-weak:  oklch(0.96 0.04 255);
  --danger-weak:   oklch(0.62 0.19 25 / 0.08);

  /* ===== แถบเมนูซ้าย: ขาว อักษรเทาเข้ม (เมนูที่เลือก = น้ำเงินตามธีม) ===== */
  --sidebar-bg:     oklch(1 0 0);
  --sidebar-tx:     oklch(0.28 0.02 260);
  --sidebar-tx2:    oklch(0.50 0.02 255);
  --sidebar-active: oklch(0.62 0.16 255);
  --sidebar-hover:  oklch(0.95 0.012 255);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Noto Sans Thai', 'Inter', sans-serif;
  -webkit-font-smoothing: antialiased;
  color: var(--text);
  font-size: 15px;
  background: var(--app-bg);
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: oklch(0.75 0.02 255); border-radius: 4px; }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
a { color: inherit; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--app-bg);
}
.login-card {
  width: 360px; background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 12px; padding: 32px;
}
.login-head { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 24px; }
.login-title { font-weight: 700; font-size: 15px; }
.login-sub { font-size: 12px; color: var(--muted); }
.login-fields { display: flex; flex-direction: column; gap: 12px; }
.login-error { font-size: 12px; color: var(--danger); }
.login-hint { font-size: 11.5px; color: var(--muted); margin-top: 6px; text-align: center; line-height: 1.5; }

/* โลโก้จริง (ไฟล์รูป) — โลโก้เต็มมีตัวอักษรในรูป */
.brand-logo-lg { display: block; width: auto; height: auto; max-width: 170px; max-height: 150px; object-fit: contain; }
.brand-ops { display: block; width: auto; height: auto; max-width: 160px; max-height: 74px; object-fit: contain; margin-top: 4px; }
.brand-logo-sm { display: block; margin: 0 auto; width: auto; height: auto; max-width: 100%; max-height: 92px; object-fit: contain; }

/* Brand logo badge (CSS placeholder for the shop mark) */
.brand-badge {
  border-radius: 10px; background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--on-primary); flex-shrink: 0;
}
.brand-badge.lg { width: 70px; height: 69px; font-size: 26px; }
.brand-badge.sm { width: 50px; height: 36px; font-size: 20px; border-radius: 8px; }

/* ---------- App shell ---------- */
.app-shell { display: flex; height: 100vh; overflow: hidden; background: var(--app-bg); }

.sidebar {
  width: 232px; flex-shrink: 0; background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 14px; gap: 24px;
  color: var(--sidebar-tx);
}
.sidebar-brand { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 4px 8px; }
.sidebar-brand .name { font-weight: 700; font-size: 14px; line-height: 1.3; }
.sidebar-brand .sub { font-size: 11px; color: var(--sidebar-tx2); }
.nav { display: flex; flex-direction: column; gap: 8px; }
/* กลุ่มเมนูแบบพับ/ขยาย */
.nav-sec { display: flex; flex-direction: column; }
.nav-sec-head {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  background: transparent; border: none; cursor: pointer; padding: 5px 12px 4px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--sidebar-tx2);
}
.nav-sec-head:hover { color: var(--sidebar-tx); }
.nav-sec-chev { font-size: 10px; color: var(--sidebar-tx2); margin-left: 8px; }
.nav-sec-body { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 8px; border: none; background: transparent;
  color: var(--sidebar-tx); font-size: 14px; text-align: left; width: 100%;
}
.nav-item .ico { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.9; }
.nav-item:hover { background: var(--sidebar-hover); color: var(--text); }
.nav-item.active { background: var(--sidebar-active); color: oklch(1 0 0); font-weight: 600; }

.sidebar-user {
  margin-top: auto; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px; background: var(--sidebar-hover);
}
.sidebar-user .info { line-height: 1.3; overflow: hidden; flex: 1; }
.sidebar-user .info .n { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .info .r { font-size: 11px; color: var(--sidebar-tx2); }
.sidebar-user .logout { background: transparent; border: none; color: var(--sidebar-tx2); font-size: 11px; padding: 4px; }
.sidebar-user .logout:hover { color: var(--text); }

.avatar {
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: var(--on-primary); flex-shrink: 0;
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  height: 64px; flex-shrink: 0; display: flex; align-items: center;
  justify-content: space-between; padding: 0 28px; border-bottom: 1px solid var(--border);
}
.topbar .title { font-size: 19px; font-weight: 700; }
.topbar .updated { font-size: 12px; color: var(--muted); }
.content { flex: 1; overflow-y: auto; padding: 28px; }

/* Notification bell dropdown */
.notif-panel { position: absolute; top: 34px; right: 0; width: 330px; background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 28px oklch(0.2 0.03 260 / 0.18); z-index: 150; overflow: hidden; }
.notif-item { padding: 10px 14px; border-bottom: 1px solid var(--border-row); cursor: pointer; }
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--row-hover); }

/* ---------- Cards & generic ---------- */
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; }
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.muted { color: var(--muted); }

/* ---------- Dashboard ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; }
.stat .lbl { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.stat .val { font-size: 30px; font-weight: 700; }
.stat.today { border-left: 3px solid oklch(0.75 0.15 80); }
.stat.overdue { border-left: 3px solid oklch(0.62 0.19 25); }
.stat.unreachable { border-left: 3px solid oklch(0.60 0.02 260); }
.stat.closed { border-left: 3px solid oklch(0.70 0.15 145); }

.dash-cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
.dash-left { display: flex; flex-direction: column; gap: 20px; }

/* Management dashboard */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.kpi { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; }
.kpi-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kpi-value { font-size: 30px; font-weight: 700; line-height: 1.1; }
.kpi-sub { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.dash-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.dash-2.wide { grid-template-columns: 1.5fr 1fr; }
.prov-row { display: grid; grid-template-columns: 1.2fr 1.7fr 66px 70px; gap: 10px; align-items: center; padding: 9px 6px; border-bottom: 1px solid var(--border-row); font-size: 13px; }
.prov-row.clickable { cursor: pointer; border-radius: 6px; }
.prov-row.clickable:hover { background: var(--row-hover); }
.prov-head { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--border); }
.prov-bar { position: relative; background: oklch(0.93 0.012 255); border-radius: 5px; height: 16px; overflow: hidden; }
.prov-bar > div { height: 100%; border-radius: 5px; }
.prov-bar > span { position: absolute; right: 7px; top: 0; line-height: 16px; font-size: 11px; color: var(--text-2); font-weight: 600; }
.range-btn { background: var(--input-bg); border: 1px solid var(--border); border-radius: 7px; padding: 4px 10px; font-size: 11.5px; color: var(--muted); cursor: pointer; font-family: inherit; }
.range-btn.on { background: var(--primary); color: var(--on-primary); border-color: var(--primary); font-weight: 600; }
.list-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 8px; border-bottom: 1px solid var(--border-row);
}
.list-row.clickable { cursor: pointer; }
.list-row.clickable:hover { background: var(--row-hover); }
.list-row .primary { font-size: 13.5px; font-weight: 600; }
.list-row .secondary { font-size: 12px; color: var(--muted); }
.list-row .meta { font-size: 12px; color: var(--muted); }
.list-row .meta.due { color: var(--danger); }
.card-title.danger { color: var(--danger); }

.perf-item .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.perf-item .top .n { font-weight: 600; }
.perf-item .top .s { color: var(--muted); }
.bar { height: 8px; border-radius: 4px; background: oklch(0.92 0.012 255); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 4px; background: var(--primary); }
.perf-list { display: flex; flex-direction: column; gap: 16px; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; gap: 12px; margin-bottom: 18px; align-items: center; flex-wrap: wrap; }
.result-count { font-size: 12px; color: var(--muted); margin-bottom: 10px; }

.input, .select, .textarea {
  background: var(--card-bg); border: 1px solid var(--input-border); border-radius: 8px;
  padding: 10px 14px; color: var(--text); font-size: 13.5px;
}
.input.grow { flex: 1; min-width: 220px; }
.textarea { resize: vertical; }
/* ดรอปดาวน์: ลูกศรชี้ลงแบบกำหนดเอง จัดกึ่งกลางแนวตั้ง สีเทากลางให้บาลานซ์กับข้อความ */
.select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23697079' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 15px;
}
.select.sm { padding-right: 28px; background-position: right 9px center; background-size: 13px; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid oklch(0.62 0.16 255 / 0.4); outline-offset: 0; }

.btn {
  border: none; border-radius: 8px; padding: 11px 20px;
  color: var(--on-primary); font-weight: 600; font-size: 13.5px; background: var(--primary);
  white-space: nowrap; letter-spacing: 0.01em;
  box-shadow: 0 1px 2px oklch(0.2 0.03 260 / 0.12); transition: filter 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.btn:hover { filter: brightness(1.06); box-shadow: 0 2px 6px oklch(0.2 0.03 260 / 0.16); }
.btn:active { box-shadow: 0 1px 1px oklch(0.2 0.03 260 / 0.14); }
.btn.ghost { background: transparent; border: 1px solid var(--btn-border); color: var(--text-2); font-weight: 500; box-shadow: none; filter: none; }
.btn.ghost:hover { background: var(--row-hover); border-color: var(--muted); box-shadow: none; }
.btn.sm { padding: 6px 12px; font-size: 11.5px; }
.btn.block { display: block; }
.btn.danger { background: var(--danger); color: oklch(1 0 0); }
.btn.danger:hover { filter: brightness(1.05); }
.btn.danger.ghost { background: transparent; border: 1px solid var(--danger); color: var(--danger); box-shadow: none; }
.btn.danger.ghost:hover { background: var(--danger-weak); filter: none; }

/* ---------- Customer table ---------- */
.table-wrap { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; overflow-x: auto; }
.cust-grid {
  display: grid;
  grid-template-columns: 76px minmax(0,1.4fr) minmax(0,1.2fr) minmax(0,0.8fr) 82px 82px 104px 46px;
  gap: 6px; padding: 12px 14px; min-width: 1020px; align-items: center;
}
.cust-head {
  font-size: 11px; color: var(--muted); border-bottom: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: 0.03em;
}
.cust-row { border-bottom: 1px solid var(--border-row); font-size: 12.5px; cursor: pointer; }
.cust-row:hover { background: var(--row-hover); }
.cust-row .row-go { text-align: right; color: var(--muted); font-size: 20px; line-height: 1; }
.cust-row:hover .row-go { color: var(--text); }
.cust-row .id { color: var(--muted); font-size: 11.5px; }
.cust-row .shop { font-weight: 600; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.dim { font-size: 11.5px; color: var(--muted); }
.pill {
  display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 999px;
  font-size: 10.5px; font-weight: 600; color: var(--on-primary); white-space: nowrap;
}
.pill.lg { padding: 5px 12px; font-size: 12px; }

/* ---------- Detail ---------- */
.back-link { background: transparent; border: none; color: var(--muted); font-size: 13px; margin-bottom: 16px; padding: 0; }
.back-link:hover { color: var(--text); }
.detail-cols { display: grid; grid-template-columns: 1fr 1.3fr; gap: 20px; align-items: start; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.detail-head .shop { font-size: 19px; font-weight: 700; }
.detail-head .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; font-size: 13px; }
.detail-grid .full { grid-column: 1 / 3; }
.field-label { color: var(--muted); font-size: 11.5px; margin-bottom: 3px; }
.detail-right { display: flex; flex-direction: column; gap: 16px; }

.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tag-btn { border-radius: 999px; padding: 5px 12px; font-size: 12px; border: 1px solid var(--btn-border); background: transparent; color: var(--text-2); }
.tag-btn.on { border-color: var(--primary); background: var(--primary); color: var(--on-primary); }

.collapse-head { display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.timeline { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; overflow-y: auto; }
.timeline.contacts { max-height: 420px; }
.timeline.edits { max-height: 280px; gap: 12px; }
.tl-item { border-left: 2px solid var(--primary); padding-left: 12px; }
.tl-item.edit { border-left-color: var(--btn-border); }
.tl-item .when { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.tl-item .result { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.tl-item .note { font-size: 12.5px; color: var(--text-2); }
.tl-item .tags { font-size: 11.5px; color: var(--primary); margin-top: 3px; }
.tl-item .chg { font-size: 12.5px; margin-bottom: 2px; }

/* ---------- Users ---------- */
.users-toolbar { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.lock-note { font-size: 11.5px; color: var(--muted); }
.users-wrap { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 24px; }
.users-grid { display: grid; grid-template-columns: 1fr 0.9fr 0.9fr 0.8fr 1.3fr 150px; gap: 8px; padding: 13px 16px; align-items: center; font-size: 13px; }
.users-head { font-size: 11.5px; color: var(--muted); border-bottom: 1px solid var(--border); text-transform: uppercase; padding: 12px 16px; }
.users-row { border-bottom: 1px solid var(--border-row); }
.users-row .who { display: flex; align-items: center; gap: 10px; }
.section-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
/* หัวข้อ + แถบเครื่องมือ (โน้ต+ปุ่ม) อยู่บรรทัดเดียวกัน */
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px 20px; flex-wrap: wrap; margin: 24px 0 12px; }
.section-head .section-title { margin: 0; }
.section-head .users-toolbar { margin: 0; }
@media (max-width: 700px) { .section-head .users-toolbar { width: 100%; justify-content: flex-start; } }
.audit-wrap { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.audit-grid { display: grid; grid-template-columns: 150px 1fr 1.4fr 1.4fr; gap: 8px; padding: 12px 16px; font-size: 12.5px; }
.audit-head { font-size: 11.5px; color: var(--muted); border-bottom: 1px solid var(--border); text-transform: uppercase; }
.audit-row { border-bottom: 1px solid var(--border-row); }

/* ---------- Modal / forms ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: oklch(0.25 0.05 255 / 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal { background: var(--card-bg); border: 1px solid var(--input-border); border-radius: 12px; padding: 26px; max-height: 85vh; overflow-y: auto; }
.modal.wide { width: 640px; }
.modal.narrow { width: 520px; }
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-col { display: flex; flex-direction: column; gap: 12px; }
.field { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / 3; }
.field .input, .field .select, .field .textarea { font-size: 13px; padding: 9px 11px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 22px; }
.perm-list { display: flex; flex-direction: column; gap: 2px; }
.perm-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.perm-item:hover { background: var(--input-bg); }
.perm-item input { width: 16px; height: 16px; accent-color: var(--primary); }
.checkbox { width: 16px; height: 16px; accent-color: var(--primary); }

@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-cols, .dash-2, .dash-2.wide { grid-template-columns: 1fr; }
  .detail-cols { grid-template-columns: 1fr; }
}

/* ---------- เรียลไทม์: แถบคนที่กำลังดูหน้านี้ ---------- */
.rt-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 0 0 14px; padding: 8px 12px; border-radius: 10px;
  background: oklch(0.96 0.03 255); border: 1px solid oklch(0.88 0.04 255);
  font-size: 12.5px;
}
.rt-live {
  width: 8px; height: 8px; border-radius: 50%; background: oklch(0.68 0.17 145);
  box-shadow: 0 0 0 0 oklch(0.68 0.17 145 / 0.7); animation: rt-pulse 2s infinite; flex: none;
}
@keyframes rt-pulse {
  0%   { box-shadow: 0 0 0 0 oklch(0.68 0.17 145 / 0.6); }
  70%  { box-shadow: 0 0 0 7px oklch(0.68 0.17 145 / 0); }
  100% { box-shadow: 0 0 0 0 oklch(0.68 0.17 145 / 0); }
}
.rt-label { color: oklch(0.45 0.03 260); font-weight: 500; }
.rt-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card, #fff); border: 1px solid oklch(0.88 0.03 255);
  border-radius: 999px; padding: 3px 10px 3px 3px; font-weight: 600;
  color: oklch(0.32 0.02 260);
}
.rt-av {
  width: 20px; height: 20px; border-radius: 50%; color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; flex: none;
}
.rt-typing { color: oklch(0.55 0.15 255); font-weight: 500; margin-left: 2px; }
.rt-typing i {
  display: inline-block; width: 3px; height: 3px; border-radius: 50%; margin-left: 2px;
  background: oklch(0.55 0.15 255); animation: rt-dot 1.2s infinite;
}
.rt-typing i:nth-child(2) { animation-delay: 0.2s; }
.rt-typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes rt-dot { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

/* ---------- เรียลไทม์: รูปคนที่กำลังดู ในแถวรายชื่อลูกค้า ---------- */
.rt-watch {
  display: inline-flex; align-items: center; gap: 3px; margin-left: 8px;
  vertical-align: middle; padding: 2px 7px 2px 6px; border-radius: 999px;
  background: oklch(0.95 0.04 145); border: 1px solid oklch(0.85 0.07 145);
}
.rt-live.sm { width: 6px; height: 6px; margin-right: 2px; }
.rt-av.sm { width: 17px; height: 17px; font-size: 9px; border: 1.5px solid #fff; margin-left: -5px; }
.rt-av.sm:first-of-type { margin-left: 0; }
.rt-av.sm.typing { box-shadow: 0 0 0 2px oklch(0.65 0.16 255 / 0.55); }
.rt-more { font-size: 10px; font-weight: 700; color: oklch(0.42 0.06 145); margin-left: 2px; }

/* ================================================================
   รองรับมือถือ / แท็บเล็ต
   จอคอม (กว้างเกิน 900px) ใช้เลย์เอาต์เดิมทุกอย่าง ไม่กระทบ
   ================================================================ */

/* ปุ่ม ☰ และฉากหลังของลิ้นชัก — ซ่อนไว้บนจอคอม */
.nav-toggle { display: none; background: transparent; border: none; font-size: 22px; line-height: 1; padding: 4px 6px; cursor: pointer; color: var(--text); }
.nav-scrim { display: none; }

@media (max-width: 900px) {
  /* ---------- เมนูซ้าย -> ลิ้นชักเลื่อนออกจากขอบซ้าย ---------- */
  .app-shell { position: relative; }
  .nav-toggle { display: block; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 120; width: 250px;
    transform: translateX(-100%); transition: transform 0.22s ease;
    overflow-y: auto;
  }
  .app-shell.nav-open .sidebar { transform: translateX(0); box-shadow: 0 0 40px oklch(0.2 0.05 260 / 0.35); }
  .nav-scrim { display: block; position: fixed; inset: 0; z-index: 110; background: oklch(0.25 0.05 255 / 0.45); }
  .nav-item { padding: 13px 12px; }          /* แตะง่ายขึ้น */

  /* ---------- แถบบน ---------- */
  .topbar { height: 56px; padding: 0 14px; gap: 10px; }
  .topbar .title { font-size: 16px; }
  .topbar .updated { display: none; }        /* ประหยัดที่ */
  .content { padding: 16px 14px 28px; }
  .notif-panel { position: fixed; top: 56px; left: 10px; right: 10px; width: auto; }

  /* ---------- แดชบอร์ด ---------- */
  .stat-grid, .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-grid { margin-bottom: 16px; }
  .dash-2.wide { grid-template-columns: 1fr; }

  /* ---------- ตารางที่กว้างเกินจอ: ให้เลื่อนในกรอบตัวเอง ---------- */
  .users-wrap, .audit-wrap, .table-wrap { -webkit-overflow-scrolling: touch; }

  /* ---------- ฟอร์ม / กล่องโต้ตอบ ---------- */
  .modal-overlay { align-items: flex-end; }   /* เด้งขึ้นจากขอบล่างแบบแอป */
  .modal, .modal.wide, .modal.narrow {
    width: 100%; max-width: 100%; max-height: 92vh;
    border-radius: 16px 16px 0 0; padding: 20px 16px 24px;
  }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: 1 / 2; }
  .modal-actions { position: sticky; bottom: -24px; background: var(--card-bg); padding: 12px 0 0; margin-top: 16px; }
  .modal-actions .btn { flex: 1; }            /* ปุ่มเต็มความกว้าง กดง่าย */

  /* ---------- หน้ารายละเอียดลูกค้า ---------- */
  .detail-grid { grid-template-columns: 1fr; }
  .detail-grid .full { grid-column: 1 / 2; }

  /* ---------- แถบค้นหา/ตัวกรอง ---------- */
  .toolbar { gap: 8px; }
  .toolbar .input.grow { min-width: 100%; }
  .toolbar .select, .toolbar .btn { flex: 1; min-width: 140px; }

  /* ---------- นิ้วกดได้ถนัด ---------- */
  .btn { min-height: 40px; }
  .input, .select, .textarea { font-size: 16px; }  /* 16px กันไม่ให้ iOS ซูมเองตอนโฟกัส */
}

/* ---------- รายชื่อลูกค้า: ตาราง -> การ์ดใบละราย ---------- */
@media (max-width: 760px) {
  .table-wrap { border: none; background: transparent; overflow-x: visible; }
  .cust-head { display: none; }
  .cust-grid { min-width: 0; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px; padding: 0; }
  .cust-row {
    background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px;
    padding: 13px 14px; margin-bottom: 10px; font-size: 13px;
  }
  /* จัดตำแหน่งลูกทั้ง 8 ช่องใหม่เป็นการ์ด */
  .cust-row > *:nth-child(2) { grid-column: 1; grid-row: 1; }            /* ชื่อกิจการ + ชื่อลูกค้า */
  .cust-row > *:nth-child(7) { grid-column: 2; grid-row: 1; justify-self: end; align-self: start; }  /* สถานะ */
  .cust-row > *:nth-child(1) { grid-column: 1 / -1; grid-row: 2; }       /* รหัส */
  .cust-row > *:nth-child(3) { grid-column: 1 / -1; grid-row: 3; }       /* พื้นที่ */
  .cust-row > *:nth-child(4) { grid-column: 1 / -1; grid-row: 4; }       /* ผู้รับผิดชอบ */
  .cust-row > *:nth-child(5) { grid-column: 1; grid-row: 5; }            /* ติดต่อล่าสุด */
  .cust-row > *:nth-child(6) { grid-column: 2; grid-row: 5; justify-self: end; }  /* ครบกำหนด */
  .cust-row > *:nth-child(8) { display: none; }  /* ลูกศร › — ทั้งการ์ดแตะได้อยู่แล้ว ไม่ต้องโชว์ */
  /* ชื่อยาวให้ตกบรรทัดได้ และปลดการตัดข้อความ ไม่งั้นป้ายเคลมจะโดนเฉือนที่ขอบการ์ด */
  .cust-row .shop { font-size: 14px; white-space: normal; overflow: visible; text-overflow: clip; }
  .cust-row .shop .pill { white-space: normal; margin-left: 0; margin-top: 4px; }
  .cust-row .id { font-size: 11px; }
  /* แถบ "กำลังดูหน้านี้อยู่ด้วย" ให้ตกบรรทัดได้ ไม่ชนขอบจอ */
  .rt-bar { padding: 8px 10px; }
  .rt-chip { max-width: 100%; flex-wrap: wrap; }

  .cust-row > *:nth-child(4)::before { content: "ผู้รับผิดชอบ: "; color: var(--muted); }
  .cust-row > *:nth-child(5)::before { content: "ติดต่อล่าสุด "; }
  .cust-row > *:nth-child(6)::before { content: "ครบกำหนด "; }
}

/* ---------- จอเล็กมาก (iPhone SE ฯลฯ) ---------- */
@media (max-width: 400px) {
  .stat-grid, .kpi-grid { grid-template-columns: 1fr; }
  .toolbar .select { min-width: calc(50% - 4px); }  /* ตัวกรอง 2 ช่องเรียงคู่กัน */
  .toolbar .btn { min-width: 100%; }
  .rt-bar { font-size: 11.5px; }
}

/* ---------- หน้าล็อกอินบนมือถือ ---------- */
@media (max-width: 420px) {
  .login-card { width: 100%; max-width: 100%; padding: 26px 20px; border-radius: 0; border-left: none; border-right: none; }
  .login-screen { align-items: flex-start; padding-top: 40px; }
}

/* ---------- จัดการสิทธิ์ + ประวัติแก้ไข + ตารางจังหวัด -> การ์ด ---------- */
@media (max-width: 760px) {
  .users-wrap, .audit-wrap { background: transparent; border: none; overflow: visible; }
  .users-head, .audit-head { display: none; }
  .users-grid, .audit-grid { grid-template-columns: 1fr; gap: 4px; padding: 0; }
  .users-row, .audit-row {
    background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px;
    padding: 13px 14px; margin-bottom: 10px;
  }
  .users-row .who { font-weight: 600; font-size: 14px; }
  .perm-row > *:nth-child(4)::before { content: "สิทธิ์: "; }
  .users-row > *:nth-child(6) { margin-top: 9px; }
  .users-row > *:nth-child(6) .btn { flex: 1; }
  .audit-row > *:nth-child(3) { font-weight: 600; }

  /* ตารางจังหวัดในแดชบอร์ด: ยุบแถบกราฟลงบรรทัดใหม่ */
  .prov-head { display: none; }
  .prov-row { grid-template-columns: 1fr auto auto; gap: 6px 10px; }
  .prov-row > *:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
}

/* ---------- แท็บย่อย (จัดการรถขนส่ง: รายการรถ / แพลนงานส่ง / ติดตาม) ---------- */
.subtabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.subtab {
  background: transparent; border: none; padding: 9px 16px; font-size: 13.5px; font-weight: 600;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.subtab:hover { color: var(--text); }
.subtab.active { color: oklch(0.55 0.17 255); border-bottom-color: oklch(0.55 0.17 255); }
@media (max-width: 760px) {
  .subtabs { overflow-x: auto; }
  .subtab { white-space: nowrap; padding: 9px 13px; }
}

/* ---------- ห้องควบคุมขนส่ง (dispatcher) ---------- */
.dispatch-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.dispatch-head { padding: 12px 16px; font-weight: 700; font-size: 13.5px; border-bottom: 1px solid var(--border); background: oklch(0.97 0.008 255); }
.input.sm, .select.sm { padding: 6px 9px; font-size: 12.5px; }

/* คิวออเดอร์ (ซ้าย) */
.q-list { max-height: 62vh; overflow-y: auto; }
.q-row { display: grid; grid-template-columns: 20px 1fr 90px; gap: 8px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border-row); }
.q-row[draggable] { cursor: grab; }
.q-row[draggable]:active { cursor: grabbing; }
.q-row:hover { background: oklch(0.97 0.03 255); }
.q-row.dragging { opacity: 0.4; }
.vrp-group { border-bottom: 1px solid var(--border-row); }
.vrp-group:last-child { border-bottom: none; }
.vrp-group-head { display: flex; align-items: center; gap: 6px; padding: 9px 14px; font-size: 12.5px; font-weight: 700; background: var(--card-bg); border-bottom: 1px solid var(--border-row); cursor: pointer; user-select: none; position: sticky; top: 0; z-index: 1; }
.vrp-group-head:hover { background: var(--row-hover); }
.vrp-group-head .vrp-chev { color: var(--muted); font-size: 11px; width: 12px; }
.q-row.q-blocked { background: oklch(0.98 0.02 25); cursor: not-allowed; }
.q-row.q-blocked:hover { background: oklch(0.96 0.04 25); }
.q-grip { color: oklch(0.72 0.02 260); font-size: 13px; line-height: 1; user-select: none; text-align: center; }
.q-info { min-width: 0; }
.q-shop { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-wt-txt { text-align: right; font-size: 12.5px; font-weight: 600; white-space: nowrap; }

/* รถเป็นจุดวาง (drop zone) */
.t-card[data-drop-gps] { transition: outline 0.1s, background 0.1s; }
.t-card.drop-hot { outline: 2px dashed var(--primary); outline-offset: 2px; background: oklch(0.96 0.04 255); }

/* รถ (ขวา) */
.t-list { max-height: 62vh; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.t-card { border: 1px solid var(--border); border-radius: 9px; padding: 11px 13px; }
.t-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.t-name { font-weight: 700; font-size: 13.5px; }
.t-cap { font-size: 12px; color: var(--muted); white-space: nowrap; }
.t-cap b { color: var(--text); font-size: 15px; }
.t-bar { height: 8px; border-radius: 5px; background: oklch(0.92 0.012 255); overflow: hidden; margin: 8px 0 5px; }
.t-bar > div { height: 100%; border-radius: 5px; transition: width 0.25s; }
.t-load { display: flex; justify-content: space-between; font-size: 11.5px; margin-bottom: 4px; }
.t-orders { border-top: 1px dashed var(--border); margin-top: 7px; padding-top: 7px; display: flex; flex-direction: column; gap: 3px; }
.t-ord { display: flex; align-items: center; gap: 7px; font-size: 12px; padding: 2px 0; }
.t-ord[draggable] { cursor: grab; }
.t-ord[draggable]:active { cursor: grabbing; }
.t-ord.dragging { opacity: 0.4; }
.t-ord.seq-hot { box-shadow: inset 0 2px 0 var(--primary); }
.t-ord .ellipsis { min-width: 0; }
.t-ord-info { flex: 1; min-width: 0; }
.t-ord-info .ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-seq { font-weight: 700; color: var(--primary); font-size: 12px; min-width: 16px; }
.t-x { background: transparent; border: none; color: oklch(0.62 0.16 25); font-size: 12px; padding: 2px 5px; border-radius: 4px; flex: none; }
.t-x:hover { background: oklch(0.94 0.05 25); }

@media (max-width: 860px) {
  .dispatch-cols { grid-template-columns: 1fr; }
  .q-list, .t-list { max-height: none; }
}

/* ---------- หน้าคนขับ: บันทึกจัดส่ง ---------- */
.job-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 15px 16px; margin-bottom: 12px; }
.job-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.job-shop { font-weight: 700; font-size: 15px; }
.job-photo { width: 100%; max-height: 320px; object-fit: cover; border-radius: 10px; margin-top: 10px; border: 1px solid var(--border); }
.job-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.btn.disabled { opacity: 0.55; pointer-events: none; }
/* จอเล็ก: ปุ่มถ่ายรูป/ส่งไม่สำเร็จ เรียงลงเต็มความกว้าง กันปุ่มล้นขอบ */
@media (max-width: 480px) { .job-actions { flex-direction: column; } .job-actions > * { width: 100%; } }

/* ---------- แผนที่ติดตามการขนส่ง ---------- */
.track-wrap { display: grid; grid-template-columns: 300px 1fr; gap: 14px; align-items: stretch; }
.track-side { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; overflow-y: auto; max-height: 66vh; }
.track-map { height: 66vh; border-radius: 10px; border: 1px solid var(--border); overflow: hidden; z-index: 0; }
.track-item { padding: 11px 13px; border-bottom: 1px solid var(--border-row); cursor: pointer; }
.track-item:hover { background: var(--row-hover); }
.track-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px oklch(1 0 0), 0 0 0 3px oklch(0.85 0.02 260); }
/* Leaflet controls above content */
.leaflet-pane, .leaflet-top, .leaflet-bottom { z-index: 1; }
@media (max-width: 860px) {
  .track-wrap { grid-template-columns: 1fr; }
  .track-side { max-height: 240px; }
  .track-map { height: 52vh; }
}

/* ปุ่มลิงก์ลูกค้าในออเดอร์ใต้รถ */
.t-link { background: transparent; border: none; color: var(--primary); font-size: 12px; padding: 2px 5px; border-radius: 4px; flex: none; }
.t-link:hover { background: oklch(0.95 0.04 255); }

/* ---------- ตำแหน่งและสิทธิ์ (RBAC) ---------- */
.role-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-bottom: 8px; }
.role-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.role-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border-row); }
.perm-grid-role { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.perm-grid-role .perm-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; cursor: pointer; }
/* ตารางผู้ใช้ (ชื่อ / ไอดี / ตำแหน่ง / จัดการ) */
.urole-grid { display: grid; grid-template-columns: 1.3fr 1fr 1.1fr 1.1fr 150px; gap: 8px; padding: 12px 16px; align-items: center; }
.urole-head { font-size: 11.5px; color: var(--muted); border-bottom: 1px solid var(--border); text-transform: uppercase; }
.urole-row { border-bottom: 1px solid var(--border-row); font-size: 13px; }
.urole-row .who { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.urole-grouphead { padding: 9px 16px; font-weight: 700; font-size: 12.5px; background: var(--row-hover); border-bottom: 1px solid var(--border); color: var(--text); }
@media (max-width: 860px) { .role-cards { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .urole-grid { grid-template-columns: 1fr; gap: 4px; padding: 0; }
  .urole-head { display: none; }
  .urole-row { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
  .urole-row > *:nth-child(4) { margin-top: 8px; }
  .urole-row > *:nth-child(4) .btn { flex: 1; }
}

/* ---------- ตำแหน่งแบบ accordion (กะทัดรัด รองรับ 100+) ---------- */
.racc-list { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--card-bg); margin-bottom: 8px; }
.racc { border-bottom: 1px solid var(--border-row); }
.racc:last-child { border-bottom: none; }
.racc-head { display: flex; align-items: center; gap: 9px; padding: 11px 14px; cursor: pointer; }
.racc-head:hover { background: var(--row-hover); }
.racc-head b { font-size: 13.5px; }
.racc-chev { color: var(--muted); font-size: 11px; width: 12px; flex: none; }
.racc-meta { margin-left: auto; font-size: 11.5px; white-space: nowrap; }
.racc.open .racc-head { background: oklch(0.97 0.01 255); }
.racc-body { padding: 6px 14px 14px 35px; }
.racc-body .perm-grid-role { grid-template-columns: 1fr 1fr; }
/* กลุ่มสิทธิ์ (แท็ปตามพื้นที่ใช้งาน) */
.perm-group { margin-bottom: 12px; }
.perm-group:last-child { margin-bottom: 0; }
.perm-group-title { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; margin: 4px 0 6px; padding-bottom: 4px; border-bottom: 1px solid var(--border-row); }
@media (max-width: 760px) {
  .racc-body { padding-left: 14px; }
  .racc-body .perm-grid-role { grid-template-columns: 1fr; }
  .racc-meta { display: none; }
}

/* ---------- แผนที่เส้นทางต่อรถ (ในแพลนงานส่ง) ---------- */
.tmap { height: 300px; border-radius: 9px; border: 1px solid var(--border); overflow: hidden; margin-top: 8px; z-index: 0; }
.tmap-pin { width: 24px; height: 24px; border-radius: 50%; background: oklch(0.55 0.17 255); color: #fff; font-weight: 700; font-size: 12px; display: flex; align-items: center; justify-content: center; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.tmap-depot { min-width: 34px; height: 22px; padding: 0 6px; border-radius: 11px; background: oklch(0.62 0.17 145); color: #fff; font-weight: 700; font-size: 11px; display: flex; align-items: center; justify-content: center; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); white-space: nowrap; }

/* ---------- ไอคอนโทนเดียว (ขาว–ดำ มืออาชีพ) ---------- */
:root { --accent-ico: oklch(0.45 0 0); }            /* เทาเข้ม บนแถบเมนูขาว */
.nav-item .ico { width: 20px; height: 20px; background: none; display: flex; align-items: center; justify-content: center; color: var(--accent-ico); opacity: 0.9; }
.nav-item .ico .nav-svg { width: 19px; height: 19px; }
.nav-item:hover .ico { color: var(--text); opacity: 1; }
.nav-item.active .ico { color: oklch(1 0 0); opacity: 1; }   /* ขาวบนพื้นแดง */
.bell-btn { position: relative; background: transparent; border: none; cursor: pointer; padding: 3px 4px; line-height: 1; color: var(--muted); transition: color 0.15s; }
.bell-btn:hover { color: var(--primary); }
.bell-svg { width: 21px; height: 21px; display: block; }

/* ---------- ไอคอน SVG ในเนื้อหา (โทนเทาเข้ม เข้าชุดตัวอักษร) ---------- */
.ci { width: 1em; height: 1em; vertical-align: -0.16em; display: inline-block; }
.ci-gold { color: oklch(0.42 0 0); display: inline-flex; vertical-align: -0.16em; }  /* เทาเข้ม อ่านง่ายบนพื้นขาว */
.ci-gold .ci { width: 1.05em; height: 1.05em; vertical-align: 0; }
.ci-w { color: #fff; display: inline-flex; }
.ci-w .ci { width: 16px; height: 16px; }
.pill .ci { width: 0.95em; height: 0.95em; }

/* ---------- ซ่อมบำรุงรถ (Maintenance) ---------- */
.mnt-add { display: grid; grid-template-columns: 180px 1fr 160px auto; gap: 8px; }
.mnt-list { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.mnt-row { display: grid; grid-template-columns: 1fr 150px 150px; gap: 10px; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--border-row); }
.mnt-row:last-child { border-bottom: none; }
.mnt-row.done > *:first-child { text-decoration: line-through; opacity: 0.6; }
@media (max-width: 760px) {
  .mnt-add { grid-template-columns: 1fr 1fr; }
  .mnt-add .input, .mnt-add .select { min-width: 0; }
  .mnt-row { grid-template-columns: 1fr; gap: 6px; }
  .mnt-row > *:last-child { justify-content: flex-start; }
}

/* ---------- บัญชี · สรุปรายงาน ---------- */
.rep-controls { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.rep-fld { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.rep-fld .input, .rep-fld .select { font-size: 13.5px; }

.rep-head { text-align: center; margin-bottom: 8px; }
.rep-title { font-size: 19px; font-weight: 700; color: var(--text); }
.rep-sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.rep-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 18px 0; }
.rep-kpi { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.rep-kpi .l { font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.rep-kpi .v { font-size: 22px; font-weight: 700; line-height: 1.1; }
.rep-kpi .v span { font-size: 12px; font-weight: 400; color: var(--muted); }
.rep-chart-title { font-size: 13px; font-weight: 600; margin: 16px 0 8px; }
.rep-table { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-top: 18px; }
.rep-row { display: grid; grid-template-columns: 1.5fr 1fr 1fr; gap: 8px; padding: 9px 14px; border-bottom: 1px solid var(--border-row); font-size: 13px; }
.rep-row:last-child { border-bottom: none; }
.rep-th { background: var(--row-hover); font-weight: 600; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.02em; }
.rep-tf { font-weight: 700; background: var(--row-hover); }
.rep-foot { text-align: right; font-size: 11px; color: var(--muted); margin-top: 12px; }
@media (max-width: 760px) { .rep-summary { grid-template-columns: repeat(2, 1fr); } }
/* จอเล็ก: ตารางรายงานกลายเป็นการ์ดเรียงลง (ไม่ต้องเลื่อนซ้าย-ขวา) */
@media (max-width: 560px) {
  .rep-table .rep-row { display: block !important; padding: 11px 14px; }
  .rep-table .rep-th { display: none !important; }
  .rep-table .rep-row > div { display: flex; justify-content: space-between; text-align: left !important; padding: 3px 0; }
  .rep-table .rep-row > div[data-l]::before { content: attr(data-l) " (กก.)"; color: var(--muted); font-weight: 400; }
  .rep-table .rep-row > div.rep-c-branch { display: block; font-weight: 700; font-size: 14px; padding: 0 0 5px; margin-bottom: 3px; border-bottom: 1px solid var(--border-row); }
  .rep-table .rep-row > div.rep-empty { display: block; text-align: center !important; }
}

/* ---------- โหมดพิมพ์ A4 ---------- */
.no-print { }
@media print {
  @page { size: A4; margin: 14mm; }
  html, body { background: #fff !important; }
  .sidebar, .topbar, .nav-scrim, .no-print, .flash-banner { display: none !important; }
  .app-shell { display: block !important; height: auto !important; overflow: visible !important; }
  .main { min-height: 0 !important; overflow: visible !important; }
  .content { overflow: visible !important; padding: 0 !important; }
  .report-print { border: none !important; box-shadow: none !important; padding: 0 !important; }
  .report-print, .report-print * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .rep-row { break-inside: avoid; }
  .rep-table { border-color: #999 !important; }
}

/* ---------- รองรับมือถือจอเล็กสุด (กันเนื้อหาล้นขอบขวา) ---------- */
.content { overflow-x: hidden; }               /* หน้าหลักไม่เลื่อนแนวนอน — ตารางกว้างเลื่อนในกรอบตัวเอง */
/* grid/flex item ต้อง min-width:0 ไม่งั้นเนื้อหากว้าง (ตารางเลื่อนได้) จะดันคอลัมน์จนล้นจอ */
.dash-2 > *, .dash-cols > *, .dash-left > * { min-width: 0; }
.cov-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 16px; }
.area-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 640px) {
  .cov-grid { grid-template-columns: 1fr; gap: 2px; }   /* ความครอบคลุม: อำเภอเรียงคอลัมน์เดียว */
  .area-scroll .prov-row { min-width: 360px; }          /* ตารางโฟกัส 5 คอลัมน์: เลื่อนในกรอบแทนล้นจอ */
}
@media (max-width: 400px) {
  .content { padding: 14px 10px 26px; }
  .card { padding: 15px 13px; }
  .rep-controls { gap: 10px; }
  .rep-fld { width: 100%; }
  .rep-fld .input, .rep-fld .select { width: 100%; }
}
