/* ============================================================
   base.css — "แผงควบคุมหน้าลาน" : ตัวเลขใหญ่ ปุ่มใหญ่ จอ LED
   ออกแบบสำหรับแท็บเล็ตหน้าลาน — แตะง่าย อ่านชัด
   คง class เดิมทั้งหมด (HTML/JS ไม่ต้องแก้)
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
/* font-scale ที่ html → rem ทั้งระบบ (sidebar/nav/modal) scale ตามอัตโนมัติ */
html { -webkit-text-size-adjust: 100%; font-size: calc(16px * var(--font-scale)); }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  /* ลายผ้าใบ/กระดาษบาง ๆ ให้ดูเป็นหน้างานจริง ไม่ใช่ template เปล่า */
  background-image:
    radial-gradient(circle at 1px 1px, var(--bg-grain) 1px, transparent 0);
  background-size: 22px 22px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
h1,h2,h3,h4 { margin: 0 0 .4em; font-weight: 700; line-height: 1.2; }
input, select, textarea, button { font-family: var(--font); font-size: inherit; }
/* บังคับ var(--font) ทุกปุ่ม/คอนโทรล กัน user-agent style แทรก (ฟอนต์ไม่เปลี่ยนตาม pref) */
.btn, .choice, .opt-card, .tab, .um-item, .font-card, .theme-card { font-family: var(--font); }
.mono, .num, .big-num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
/* UIcons — จัดให้อยู่กลางแนวดิ่งเทียบข้อความ */
i.fi { display: inline-flex; align-items: center; vertical-align: -0.135em; line-height: 1; }
.btn i.fi { font-size: 1.05em; }
h1 i.fi, .card-title i.fi { font-size: .95em; }

/* ============ LAYOUT ============ */
.layout { display: flex; min-height: 100vh; }

/* ---- Sidebar = "rail" แผงเมนูด้านข้าง ---- */
.sidebar {
  width: var(--rail-w); flex: 0 0 var(--rail-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; z-index: 40;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 20px 18px 18px;
  border-bottom: 1px solid var(--border);
  position: relative; color: var(--text); text-decoration: none;
  transition: background .12s;
}
.brand:hover { background: var(--surface-2); }
.brand::after { /* แถบสัญญาณใต้แบรนด์ */
  content: ''; position: absolute; left: 18px; right: 18px; bottom: -1px; height: 2px;
  background: linear-gradient(90deg, var(--primary), transparent);
}
.brand-mark {
  font-size: 22px; width: 42px; height: 42px; flex: none;
  display: grid; place-items: center;
  background: var(--primary-tint); border-radius: 12px;
}
.brand-name { font-weight: 800; font-size: 1.06rem; letter-spacing: .2px; }
/* มีโลโก้: แสดงเต็มความกว้าง ไม่มีตัวหนังสือ */
.brand-has-logo { padding: 18px 12px; justify-content: center; }
.brand-logo-full { max-width: 100%; max-height: 76px; object-fit: contain; }

/* อัปโหลดโลโก้/favicon (หน้าตั้งค่า) */
.brand-upload-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 640px){ .brand-upload-row { grid-template-columns: 1fr; } }
.brand-upload { display: flex; flex-direction: column; gap: 10px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.brand-upload-label { font-weight: 700; font-size: .85rem; }
.brand-preview {
  width: 100%; min-height: 90px; max-height: 130px; display: grid; place-items: center;
  background: var(--surface); border: 1.5px dashed var(--border-strong); border-radius: var(--radius-sm);
  overflow: hidden; padding: 10px; cursor: pointer; transition: border-color .12s, background .12s;
}
.brand-preview:hover { border-color: var(--primary); background: var(--primary-tint); }
.brand-preview.drag-over { border-color: var(--primary); background: var(--primary-tint); border-style: solid; }
.brand-preview .muted { pointer-events: none; text-align: center; font-size: .85rem; }
.brand-preview img { max-width: 100%; max-height: 110px; object-fit: contain; pointer-events: none; }
.brand-preview.sq { aspect-ratio: 1; max-width: 130px; }
.brand-upload .btn input[type=file] { display: none; }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 13px;
  padding: 12px 13px; border-radius: var(--radius-sm);
  color: var(--text-soft); font-weight: 600;
  position: relative; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-tint); color: var(--primary); }
.nav-item.active::before {
  content: ''; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 4px;
  background: var(--primary); border-radius: 0 4px 4px 0;
}
.nav-icon { font-size: 1.22rem; width: 26px; text-align: center; flex: none; }
.nav-label { font-size: .98rem; }
.sidebar-foot { padding: 14px 18px; border-top: 1px solid var(--border); }
.ver { font-size: .72rem; color: var(--text-faint); letter-spacing: .3px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 22px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.topbar-title { font-weight: 700; font-size: 1.1rem; }
.topbar-spacer { flex: 1; }
.user-chip {
  text-align: right; line-height: 1.18; padding-right: 4px;
}
.user-name { display: block; font-weight: 700; font-size: .92rem; }
.user-role {
  display: inline-block; font-size: .68rem; font-weight: 700; letter-spacing: .4px;
  color: var(--primary); background: var(--primary-tint);
  padding: 1px 8px; border-radius: 999px; margin-top: 2px;
}

/* ============ USER MENU (dropdown มุมบนขวา) ============ */
.usermenu { position: relative; }
.usermenu-trigger {
  display: flex; align-items: center; gap: 11px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 12px 6px 6px; cursor: pointer; font-family: inherit; color: var(--text);
  transition: background .12s, border-color .12s;
}
.usermenu-trigger:hover { background: var(--surface-2); border-color: var(--border-strong); }
.usermenu.open .usermenu-trigger { background: var(--surface-2); border-color: var(--primary); }
.usermenu-avatar {
  width: 38px; height: 38px; flex: none; border-radius: 11px;
  background: var(--primary); color: var(--primary-ink);
  display: grid; place-items: center; font-weight: 800; font-size: 1.1rem;
}
.usermenu-avatar.lg { width: 46px; height: 46px; border-radius: 13px; font-size: 1.35rem; }
.usermenu-trigger .user-chip { text-align: left; padding: 0; }
.usermenu-caret { color: var(--text-soft); font-size: .8rem; transition: transform .15s; }
.usermenu.open .usermenu-caret { transform: rotate(180deg); }

.usermenu-panel {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 60;
  width: 320px; background: var(--surface);
  border: 1.5px solid var(--border-strong); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); overflow: hidden;
  opacity: 0; visibility: hidden; transform: translateY(-8px) scale(.98);
  transform-origin: top right; transition: opacity .15s, transform .15s, visibility .15s;
}
.usermenu.open .usermenu-panel { opacity: 1; visibility: visible; transform: none; }

.um-head {
  display: flex; align-items: center; gap: 13px;
  padding: 18px 18px; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.um-head-info { min-width: 0; }
.um-name { font-weight: 800; font-size: 1.05rem; }
.um-meta { font-size: .8rem; color: var(--text-soft); margin-top: 3px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.um-meta .badge { font-size: .68rem; padding: 1px 8px; }

.um-section { padding: 10px 10px; border-bottom: 1px solid var(--border); }
.um-section-last { border-bottom: 0; }
.um-section-title { font-size: .68rem; font-weight: 800; letter-spacing: .5px; text-transform: uppercase; color: var(--text-faint); padding: 4px 8px 8px; }

.um-theme-row { display: flex; gap: 6px; padding: 0 4px; }
.um-theme {
  flex: 1; appearance: none; cursor: pointer; font-family: inherit;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
  color: var(--text-soft); font-weight: 700; font-size: .82rem; padding: 9px 4px; transition: .12s;
}
.um-theme:hover { background: var(--surface-2); }
.um-theme.active { border-color: var(--primary); color: var(--primary); background: var(--primary-tint); }

.um-color-row { display: flex; gap: 8px; padding: 12px 8px 4px; }
.um-color {
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  background: var(--c); border: 2px solid transparent; transition: transform .1s, border-color .12s;
}
.um-color:hover { transform: scale(1.15); }
.um-color.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--c); }

.um-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 11px 12px; border-radius: var(--radius-sm);
  color: var(--text); font-weight: 600; font-size: .95rem;
  background: none; border: 0; font-family: inherit; cursor: pointer; text-align: left;
}
.um-item span { font-size: 1.1rem; width: 22px; text-align: center; }
.um-item:hover { background: var(--surface-2); }
.um-danger { color: var(--danger); }
.um-danger:hover { background: var(--danger-tint); }

@media (max-width: 560px) {
  .usermenu-trigger .user-chip { display: none; }
  .usermenu-panel { width: 290px; }
}

.content { padding: var(--space); max-width: 1340px; width: 100%; margin: 0 auto; }

.icon-btn {
  width: 46px; height: 46px; border: 1px solid var(--border);
  background: var(--surface); border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.25rem; cursor: pointer; color: var(--text); transition: .12s;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
#menuToggle { display: none; }

.sidebar-backdrop { display: none; }
@media (max-width: 920px) {
  :root { --rail-w: 248px; }
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow-lg); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 35; }
  #menuToggle { display: inline-flex; }
}

/* กราฟ canvas — responsive เต็มความกว้างการ์ด (สูงคงที่ตาม attr height) */
.card canvas { display: block; width: 100%; max-width: 100%; }

/* ============ PAGE HEAD ============ */
.page-head { display: flex; align-items: center; gap: 13px; flex-wrap: wrap; margin-bottom: var(--space); }
.page-head h1 { font-size: 1.5rem; margin: 0; display: flex; align-items: center; gap: 10px; }
.page-head .spacer { flex: 1; }

/* ============ DASHBOARD WIDGETS (drag & drop จัดวาง) ============ */
.dash-toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--primary-tint); border: 1px solid var(--primary);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: var(--space);
  color: var(--primary); font-weight: 600; font-size: .9rem;
}
.dash-toolbar i.fi { color: var(--primary); }
.widget { margin-bottom: var(--space); }
.widget-hidden { display: none !important; }
/* แถบหัว widget (เห็นเฉพาะโหมดแก้ไข) */
.widget-bar { display: none; align-items: center; gap: 10px; margin-bottom: 8px; }
.widget-name { font-weight: 700; font-size: .92rem; color: var(--text-soft); }
.widget-eye {
  margin-left: auto; width: 32px; height: 32px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-soft);
  display: inline-flex; align-items: center; justify-content: center;
}
.widget-eye:hover { background: var(--surface-2); color: var(--primary); }

/* โหมดแก้ไข: แสดงแถบหัว + กรอบลาก + การ์ดที่ซ่อนเป็นจาง */
body.dash-editing .widget-bar { display: flex; }
body.dash-editing .widget {
  border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 12px;
  cursor: grab; background: var(--surface-2);
}
body.dash-editing .widget:hover { border-color: var(--primary); }
body.dash-editing .widget.dragging { opacity: .5; border-color: var(--primary); }
/* ในโหมดแก้ไข widget ที่ซ่อนยังแสดงแบบจาง (ให้กดเปิดคืนได้) */
body.dash-editing .widget-hidden { display: block !important; opacity: .4; }
body.dash-editing .widget-hidden .widget-bar { opacity: 1; }

/* ============ FILTER BAR (แถบกรอง/ช่วงวันที่) ============ */
.filter-bar { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.filter-field { display: flex; flex-direction: column; gap: 6px; min-width: 180px; }
.filter-field label { font-weight: 700; font-size: .8rem; color: var(--text-soft); }
.filter-field .flatpickr-input, .filter-field input { min-width: 180px; }
.filter-arrow { color: var(--text-faint); font-size: 1.3rem; font-weight: 700; padding-bottom: 11px; }
.filter-actions { display: flex; gap: 10px; margin-left: auto; align-items: flex-end; }
.scope-badge { align-self: center; }
.scope-badge .badge { font-size: .82rem; padding: 6px 14px; }
@media (max-width: 680px) {
  .filter-field { flex: 1 1 100%; min-width: 0; }
  .filter-arrow { display: none; }
  .filter-actions { width: 100%; margin-left: 0; }
  .filter-actions .btn { flex: 1; }
}

/* ============ CARDS / PANELS ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space);
  margin-bottom: var(--space);
}
.card-title {
  font-size: .82rem; font-weight: 800; letter-spacing: .6px; text-transform: uppercase;
  color: var(--text-soft); margin: 0 0 14px;
  display: flex; align-items: center; gap: 8px;
}
.card-title::before { /* จุดสถานะนำหน้าหัวข้อ */
  content: ''; width: 8px; height: 8px; border-radius: 2px; background: var(--primary); flex: none;
}
.grid { display: grid; gap: calc(var(--space) + 6px); margin-bottom: calc(var(--space) + 6px); }
.grid:last-child { margin-bottom: 0; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1040px){ .grid-4 { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 980px){ .grid-3 { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 640px){ .grid-2,.grid-3,.grid-4 { grid-template-columns: 1fr; } }

/* ============ STAT TILES = จอ readout ============ */
.stat {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px 24px; box-shadow: var(--shadow);
}
.stat .label {
  font-size: .82rem; font-weight: 700; letter-spacing: .2px; color: var(--text-soft);
  display: flex; align-items: center; gap: 8px; text-transform: none;
}
.stat .label i.fi { font-size: 1.1em; color: var(--primary); }
.stat .value {
  font-family: var(--font-num); font-variant-numeric: tabular-nums;
  font-size: 2.3rem; font-weight: 700; margin-top: 14px; line-height: 1; letter-spacing: -.5px;
}
.stat .sub { font-size: .78rem; color: var(--text-faint); margin-top: 10px; }
/* แถบ accent ด้านซ้าย — inset เคารพมุมโค้ง ไม่ตัดเส้นกรอบ */
.stat.accent { padding-left: 26px; }
.stat.accent::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--primary);
}
.stat.good { border-color: color-mix(in srgb, var(--success) 35%, var(--border)); }
.stat.good .value { color: var(--success); }
.stat.bad  { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.stat.bad .value  { color: var(--danger); }
.stat.good.accent::before { background: var(--success); }
.stat.bad.accent::before  { background: var(--danger); }

/* ============ METRIC CARDS = วิดเจ็ตสรุป (ออกแบบใหม่) ============ */
.metric-grid {
  display: grid; gap: var(--space);
  grid-template-columns: repeat(4, 1fr);
}
.metric-grid:has(.metric:nth-child(2):last-child) { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 980px){ .metric-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px){ .metric-grid { grid-template-columns: 1fr; } }

.metric {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.metric::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--m-accent, var(--primary));
}
.metric:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.10); border-color: color-mix(in srgb, var(--m-accent, var(--primary)) 40%, var(--border)); }
.metric-ico {
  flex: none; width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--m-accent, var(--primary)) 14%, var(--surface));
  color: var(--m-accent, var(--primary));
}
.metric-ico i.fi { font-size: 1.5rem; line-height: 1; }
.metric-body { min-width: 0; flex: 1; }
.metric-label { font-size: .82rem; font-weight: 700; color: var(--text-soft); letter-spacing: .2px; }
.metric-value {
  font-family: var(--font-num); font-variant-numeric: tabular-nums;
  font-size: 1.85rem; font-weight: 700; line-height: 1.1; margin-top: 4px;
  letter-spacing: -.5px; color: var(--text); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.metric-sub { font-size: .76rem; color: var(--text-faint); margin-top: 4px; }
/* จานสีต่อ metric */
.metric.m-green  { --m-accent: #2f9e44; }
.metric.m-orange { --m-accent: #e8590c; }
.metric.m-blue   { --m-accent: #1971c2; }
.metric.m-teal   { --m-accent: #0c8599; }
.metric.m-profit { --m-accent: #2f9e44; }
.metric.m-purple { --m-accent: #7048e8; }
.metric.m-profit .metric-value { color: #2f9e44; }
@media (max-width: 400px){ .metric-value { font-size: 1.55rem; } }

/* ============ BUTTONS (ใหญ่ แตะง่าย) ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  height: var(--control-h); padding: 0 20px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-weight: 700; cursor: pointer; white-space: nowrap; user-select: none;
  transition: transform .06s, background .12s, box-shadow .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--primary); border-color: var(--primary); color: var(--primary-ink);
  box-shadow: 0 2px 0 var(--primary-700);
}
.btn-primary:hover { background: var(--primary-600); }
.btn-primary:active { box-shadow: 0 0 0 var(--primary-700); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; box-shadow: 0 2px 0 #8f2820; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-block { width: 100%; }
.btn-lg { height: calc(var(--control-h) + 10px); font-size: 1.12rem; padding: 0 26px; border-radius: var(--radius); }
.btn-sm { height: 32px; padding: 0 11px; font-size: .8rem; font-weight: 600; gap: 5px; box-shadow: none; border-radius: 7px; white-space: nowrap; }
.btn-sm i.fi { font-size: .95em; }
/* badge ในตารางจัดการ ไม่ให้ตัดบรรทัด */
table.data .badge { white-space: nowrap; }
/* ปุ่มสีอ่อนสื่อความหมาย (ใช้ในตาราง) */
.btn-soft { border-color: transparent; box-shadow: none; }
.btn-soft.primary { background: var(--primary-tint); color: var(--primary); }
.btn-soft.primary:hover { background: var(--primary); color: var(--primary-ink); }
.btn-soft.amber { background: var(--signal-tint); color: var(--signal); }
.btn-soft.amber:hover { background: var(--signal); color: #fff; }
.btn-soft.danger { background: var(--danger-tint); color: var(--danger); }
.btn-soft.danger:hover { background: var(--danger); color: #fff; }
.btn-soft.gray { background: var(--surface-3); color: var(--text-soft); }
.btn-soft.gray:hover { background: var(--text-soft); color: var(--surface); }

/* ============ CHOICE BUTTONS (ปุ่มเลือก แทน dropdown — แตะง่ายบนแท็บเล็ต) ============ */
.choice-group { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.choice {
  display: flex; align-items: center; justify-content: center; gap: 8px; text-align: center;
  min-height: 58px; padding: 10px 14px;
  border: 1.5px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-weight: 700; font-size: 1rem; cursor: pointer; user-select: none;
  transition: transform .06s, background .12s, border-color .12s, box-shadow .12s;
}
.choice:hover { background: var(--surface-2); border-color: var(--primary); }
.choice:active { transform: translateY(1px); }
.choice.active {
  background: var(--primary-tint); border-color: var(--primary); color: var(--primary);
  box-shadow: inset 0 0 0 1.5px var(--primary);
}
.choice .choice-tag { font-size: .72rem; font-weight: 700; color: var(--text-faint); }
.choice.active .choice-tag { color: var(--primary); }
.choice-group.cols-2 { grid-template-columns: repeat(2, 1fr); }
.choice-group.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 480px){ .choice-group, .choice-group.cols-3 { grid-template-columns: repeat(2, 1fr); } }

/* member choices: scroll grid (เลือกสมาชิกเป็นปุ่ม) */
.choice-scroll {
  display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  max-height: 200px; overflow-y: auto; padding: 4px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface-2);
}
.member-choice {
  min-height: 52px; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 9px 12px; font-size: .95rem;
}
.member-choice .mc-name, .walk-choice .mc-name { font-weight: 700; }
.member-choice .mc-meta, .walk-choice .mc-meta { font-size: .72rem; font-weight: 500; color: var(--text-faint); }
.member-choice.active .mc-meta, .walk-choice.active .mc-meta { color: var(--primary); }
/* ปุ่มกลุ่มราคา (ลูกค้าทั่วไป) — รูปแบบเดียวกับปุ่มสมาชิก */
.walk-choice {
  min-height: 52px; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 9px 12px; font-size: .95rem;
}
/* ตัวคั่นหมวด "สมาชิก" ในแถบเลือก */
.choice-divider {
  grid-column: 1 / -1; font-size: .72rem; font-weight: 700; color: var(--text-faint);
  padding: 6px 4px 0; letter-spacing: .3px; border-top: 1px dashed var(--border); margin-top: 2px;
}

/* ============ FORMS ============ */
.form-group { margin-bottom: 15px; }
.form-group label, .field-label {
  display: block; font-weight: 700; font-size: .8rem; letter-spacing: .2px;
  margin-bottom: 6px; color: var(--text-soft);
}
.input, input:not([type]), input[type=text], input[type=password], input[type=number], input[type=date],
input[type=tel], input[type=search], input[type=email], input[type=url], input[type=time], select, textarea {
  width: 100%; height: var(--control-h); padding: 0 14px;
  border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); transition: border-color .12s, box-shadow .12s;
}
/* กันพื้นขาว/ตัวอักษรดำจาก default ของเบราว์เซอร์ในทุกอินพุต */
input:not([type])::placeholder, input::placeholder, textarea::placeholder { color: var(--text-faint); }
/* ช่องตัวเลข = font readout */
input[type=number] { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 600; }
textarea { height: auto; padding: 11px 14px; min-height: 76px; }
select {
  appearance: none; cursor: pointer;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-soft) 50%),
    linear-gradient(135deg, var(--text-soft) 50%, transparent 50%);
  background-position: calc(100% - 19px) 52%, calc(100% - 14px) 52%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 36px;
}
input:focus, input:not([type]):focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-tint);
}
.form-row { display: grid; grid-template-columns: repeat(2,1fr); gap: 15px; }
.form-row-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 15px; }
@media (max-width: 640px){ .form-row, .form-row-3 { grid-template-columns: 1fr; } }
.hint { font-size: .78rem; color: var(--text-faint); margin-top: 5px; }
.readonly-strong { font-weight: 700; background: var(--surface-2) !important; }
input[readonly] { background: var(--surface-2); color: var(--text-soft); }
/* section divider ใน modal/form */
.form-section-label {
  font-size: .72rem; font-weight: 800; letter-spacing: .5px; text-transform: uppercase;
  color: var(--text-faint); padding: 0 0 8px; margin: 14px 0 0;
  border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px;
}
.form-section-label::before { content: ''; width: 6px; height: 6px; border-radius: 2px; background: var(--primary); flex: none; }
/* required marker */
.form-req { color: var(--danger); font-weight: 800; margin-left: 2px; }
/* hint label ใน label เดียวกัน */
.form-hint-label { font-size: .76rem; font-weight: 500; color: var(--text-faint); }

/* range slider เข้าธีม */
input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px;
  background: var(--border-strong); border-radius: 999px; cursor: pointer; padding: 0;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--primary); border: 3px solid var(--surface); box-shadow: 0 1px 4px rgba(0,0,0,.3); cursor: pointer;
}
input[type=range]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%; background: var(--primary);
  border: 3px solid var(--surface); box-shadow: 0 1px 4px rgba(0,0,0,.3); cursor: pointer;
}
.scale-slider-wrap { display: flex; align-items: center; gap: 12px; height: var(--control-h); }
.scale-end { color: var(--text-soft); font-weight: 700; flex: none; line-height: 1; }
.scale-badge {
  display: inline-block; font-family: var(--font-num); font-weight: 800; font-size: .78rem;
  color: var(--primary); background: var(--primary-tint); padding: 1px 9px; border-radius: 999px; margin-left: 4px;
}

/* ============ TABLES ============ */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table.data { width: 100%; border-collapse: collapse; background: var(--surface); }
table.data th, table.data td { padding: var(--row-pad) 15px; text-align: left; border-bottom: 1px solid var(--border); }
table.data th {
  background: var(--surface-2); font-weight: 800; font-size: .72rem; letter-spacing: .5px;
  text-transform: uppercase; color: var(--text-soft); white-space: nowrap;
  position: sticky; top: 0;
}
table.data tbody tr { transition: background .1s; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num {
  text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap;
}
table.data td.num { font-weight: 600; }
table.data tr:last-child td { border-bottom: none; }
table.data tfoot td { background: var(--surface-2); border-top: 2px solid var(--border-strong); }
/* ตารางจัดการชนิดยาง: ทุกคอลัมน์อยู่บรรทัดเดียว (กรอบ modal ขยายให้พอ) */
.rt-table th, .rt-table td { white-space: nowrap; }
.empty { padding: 40px; text-align: center; color: var(--text-faint); }

/* ============ BADGES ============ */
.badge { display: inline-block; padding: 3px 11px; border-radius: 7px; font-size: .74rem; font-weight: 800; letter-spacing: .2px; }
.badge.green { background: var(--primary-tint); color: var(--primary); }
.badge.gray  { background: var(--surface-3); color: var(--text-soft); }
.badge.red   { background: var(--danger-tint); color: var(--danger); }
.badge.amber { background: var(--signal-tint); color: var(--signal); }

/* ============ TOAST ============ */
.toast-wrap { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 11px; }
.toast {
  background: var(--surface); border: 1px solid var(--border-strong);
  border-left: 5px solid var(--primary); border-radius: var(--radius-sm);
  padding: 13px 18px; box-shadow: var(--shadow-lg); min-width: 250px; max-width: 380px;
  font-weight: 600; animation: toastIn .22s cubic-bezier(.2,.9,.3,1.2);
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.warn    { border-left-color: var(--warning); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

/* ============ MODAL ============ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(8,10,8,.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 90; padding: 16px;
  animation: fadeIn .15s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; max-height: 90vh; overflow: auto;
  animation: toastIn .2s;
}
.modal-head {
  padding: 20px 24px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-2); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.modal-head h3 { margin: 0; font-size: 1.18rem; font-weight: 800; }
/* ไฟสถานะนำหน้าชื่อ modal */
.modal-head::before {
  content: ''; display: block; width: 10px; height: 10px; border-radius: 3px;
  background: var(--primary); flex: none;
}
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; gap: 11px; justify-content: flex-end; }
.modal-close { margin-left: auto; background: none; border: 0; font-size: 1.5rem; cursor: pointer; color: var(--text-faint); line-height: 1; }
.modal-close:hover { color: var(--text); }

/* ---------- Confirm dialog ---------- */
.confirm-body { display: flex; align-items: center; gap: 16px; }
.confirm-ico {
  flex: none; width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.5rem;
  background: color-mix(in srgb, var(--primary) 14%, var(--surface)); color: var(--primary);
}
.confirm-ico i.fi { line-height: 1; }
.confirm-ico.cfk-success { background: color-mix(in srgb, var(--success) 16%, var(--surface)); color: var(--success); }
.confirm-ico.cfk-danger  { background: color-mix(in srgb, var(--danger) 14%, var(--surface));  color: var(--danger); }
.confirm-ico.cfk-warning { background: color-mix(in srgb, #e8590c 16%, var(--surface)); color: #e8590c; }
.confirm-msg { margin: 0; font-size: 1.02rem; line-height: 1.5; color: var(--text); }

/* ============ UTILITIES ============ */
.flex { display: flex; } .items-center { align-items: center; } .gap { gap: 11px; }
.gap-sm { gap: 7px; } .wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--text-soft); }
.text-right { text-align: right; } .text-center { text-align: center; }
.mt { margin-top: var(--space); } .mb0 { margin-bottom: 0; }
.big-num { font-size: 1.7rem; font-weight: 700; }
.pill-row { display: flex; flex-wrap: wrap; gap: 8px; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.danger-text { color: var(--danger); }
.success-text { color: var(--success); }

/* ============ จอชั่ง LED (พระเอกของระบบ) ============ */
.scale-box {
  background:
    radial-gradient(ellipse at 50% 0%, var(--led-bg-2), var(--led-bg));
  border: 1px solid var(--led-frame);
  border-radius: var(--radius);
  padding: 20px 22px 18px; text-align: center; margin-bottom: 16px;
  box-shadow: inset 0 2px 14px rgba(0,0,0,.6), 0 1px 0 rgba(255,255,255,.04);
  position: relative;
}
.scale-box::before { /* แถบไฟสถานะบนจอ */
  content: ''; position: absolute; top: 12px; right: 14px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--led-green); box-shadow: 0 0 8px var(--led-green); opacity: .85;
  animation: ledPulse 2s ease-in-out infinite;
}
@keyframes ledPulse { 0%,100%{opacity:.85} 50%{opacity:.3} }
.scale-box .live {
  font-family: var(--font-num); font-variant-numeric: tabular-nums;
  font-size: 3.4rem; font-weight: 700; line-height: 1; letter-spacing: 1px;
  color: var(--led-green);
  text-shadow: 0 0 12px rgba(61,245,143,.45), 0 0 30px rgba(61,245,143,.2);
}
.scale-box .live small { font-size: 1.1rem; font-weight: 600; color: var(--led-dim); text-shadow: none; letter-spacing: 0; }
.scale-status { font-size: .82rem; margin-top: 8px; color: #5c7d6c; font-weight: 600; letter-spacing: .3px; }
.scale-status.stable { color: var(--led-green); text-shadow: 0 0 8px rgba(61,245,143,.4); }
/* ปุ่มบนจอชั่งให้กลืนกับพื้นมืด */
.scale-box .btn { background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.14); color: #cfe8d8; box-shadow: none; }
.scale-box .btn:hover { background: rgba(255,255,255,.12); }
.scale-box .btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.scale-box .muted { color: #6f8c7c; }

/* ============ LOGIN ============ */
.login-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px;
  background:
    radial-gradient(1200px 500px at 80% -10%, var(--primary-tint), transparent 60%),
    var(--bg);
  background-size: auto, 22px 22px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 392px; padding: 38px 32px;
}
.login-logo {
  font-size: 34px; width: 70px; height: 70px; margin: 0 auto;
  display: grid; place-items: center; background: var(--primary-tint); border-radius: 20px;
}
.login-logo i.fi { color: var(--primary); }
.login-logo-img { max-width: 260px; max-height: 130px; width: auto; height: auto; margin: 6px auto 22px; display: block; object-fit: contain; }
.login-title { text-align: center; margin: 16px 0 2px; font-size: 1.4rem; font-weight: 800; }
.login-sub { text-align: center; color: var(--text-soft); margin: 0 0 26px; font-size: .92rem; }
.login-error {
  background: var(--danger-tint); color: var(--danger); border-radius: var(--radius-sm);
  padding: 11px 15px; margin-bottom: 15px; font-size: .9rem; font-weight: 600;
  border-left: 4px solid var(--danger);
}

/* ============ TOM SELECT — ปรับให้เข้าธีม (รองรับ dark/light) ============ */
.ts-wrapper { font-family: var(--font); }
.ts-wrapper.single .ts-control,
.ts-control {
  display: flex !important; align-items: center !important;
  min-height: var(--control-h); height: var(--control-h); padding: 0 36px 0 14px;
  border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); box-shadow: none;
  font-size: calc(16px * var(--font-scale));
}
/* รายการที่เลือก + ช่องพิมพ์ ให้ขนาดเท่า input ปกติ จัดกลางแนวตั้ง ไม่มี padding ส่วนเกิน */
.ts-control > .item, .ts-control > input {
  font-size: calc(16px * var(--font-scale)) !important; line-height: 1.4 !important;
  padding: 0 !important; margin: 0 !important; min-height: 0 !important;
}
.ts-control input, .ts-control input::placeholder { color: var(--text); }
.ts-wrapper.single .ts-control { background-image: none; } /* ลูกศร default ของ tom-select */
.ts-wrapper.single .ts-control::after {
  content: ''; position: absolute; right: 16px; top: 50%; margin-top: -3px;
  width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-top: 6px solid var(--text-soft);
}
.ts-control.focus, .ts-wrapper.focus .ts-control {
  border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-tint);
}
.ts-control .item { color: var(--text); }
.ts-dropdown {
  background: var(--surface) !important; color: var(--text) !important;
  border: 1.5px solid var(--border-strong) !important; border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow-lg) !important; margin-top: 6px; overflow: hidden; z-index: 95;
}
.ts-dropdown .ts-dropdown-content { background: var(--surface) !important; }
.ts-dropdown .option,
.ts-dropdown .create { color: var(--text) !important; background: var(--surface) !important; padding: 11px 14px; font-weight: 600; cursor: pointer; }
.ts-dropdown .option:hover,
.ts-dropdown .option.active {
  background: var(--primary-tint) !important; color: var(--primary) !important;
}
/* selected ใน dropdown (Tom Select เพิ่ม class selected) */
.ts-dropdown .option[aria-selected="true"],
.ts-dropdown .option.selected { background: var(--surface-2) !important; }
.ts-dropdown .optgroup-header {
  color: var(--text-soft); background: var(--surface-2);
  font-size: .72rem; font-weight: 800; letter-spacing: .5px; text-transform: uppercase;
}
.ts-dropdown .no-results { color: var(--text-faint); padding: 11px 14px; }
.ts-wrapper.disabled .ts-control { background: var(--surface-2); opacity: .6; }
/* ช่องค้นหาในดรอปดาวน์ */
.ts-dropdown .dropdown-input-wrap input,
.ts-control .dropdown-input {
  background: var(--surface-2); color: var(--text); border-color: var(--border);
}
/* ความกว้าง: เต็มในฟอร์ม, มี min ที่ topbar/page-head ไม่ให้บีบจนแคบ */
.ts-wrapper { width: 100%; min-width: 0; box-sizing: border-box; }
.form-group .ts-wrapper { width: 100%; }
.page-head .ts-wrapper { width: auto; min-width: 180px; }
/* ข้อความที่เลือกต้องแสดงเสมอ (กันเคสมองไม่เห็น) */
.ts-control .item { display: inline-block !important; visibility: visible !important; max-width: 100%; }

/* ============ TABS (หน้าตั้งค่า ฯลฯ) ============ */
.tabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  border-bottom: 1.5px solid var(--border); margin-bottom: var(--space);
}
.tab {
  appearance: none; background: none; border: 0; cursor: pointer;
  padding: 12px 18px; font-family: inherit; font-weight: 700; font-size: .98rem;
  color: var(--text-soft); border-bottom: 3px solid transparent; margin-bottom: -1.5px;
  display: inline-flex; align-items: center; gap: 8px; transition: color .12s, border-color .12s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn .18s; }

/* ============ SETTING CARDS (หน้ารูปลักษณ์) ============ */
.setting-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 22px 24px; margin-bottom: var(--space);
}
.setting-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.setting-ico {
  width: 48px; height: 48px; flex: none; border-radius: 14px; color: #fff;
  display: grid; place-items: center; font-size: 1.35rem;
}
.setting-ico i.fi { color: #fff; }
.setting-title { font-weight: 800; font-size: 1.15rem; }
.setting-desc { font-size: .85rem; color: var(--text-soft); margin-top: 2px; }

/* opt-grid: ปุ่มเลือกทั่วไป (โหมด/ขนาด/ไอคอน/ความหนาแน่น) */
.opt-grid { display: grid; gap: 12px; }
.opt-grid.cols-2 { grid-template-columns: repeat(2,1fr); }
.opt-grid.cols-3 { grid-template-columns: repeat(3,1fr); }
.opt-grid.cols-4 { grid-template-columns: repeat(4,1fr); }
.opt-grid.cols-6 { grid-template-columns: repeat(6,1fr); }
@media (max-width:720px){ .opt-grid.cols-6{grid-template-columns:repeat(3,1fr)} .opt-grid.cols-4{grid-template-columns:repeat(2,1fr)} }
@media (max-width:480px){ .opt-grid.cols-3,.opt-grid.cols-4,.opt-grid.cols-6{grid-template-columns:repeat(2,1fr)} }
.opt-card {
  appearance: none; cursor: pointer; font-family: inherit; color: var(--text);
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius);
  padding: 16px 10px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  transition: border-color .12s, background .12s, transform .06s;
}
.opt-card:hover { border-color: var(--primary); background: var(--surface-2); }
.opt-card:active { transform: translateY(1px); }
.opt-card i.fi { font-size: 1.5rem; color: var(--text-soft); }
.opt-card .opt-name { font-weight: 700; font-size: .98rem; }
.opt-card .opt-sub { font-size: .76rem; color: var(--text-faint); }
.opt-card.active {
  border-color: var(--primary); background: var(--primary-tint);
}
.opt-card.active i.fi, .opt-card.active .opt-name { color: var(--primary); }

/* surface card swatch */
.surface-swatch { width: 40px; height: 28px; border-radius: 7px; border: 2px solid; display: block; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* size card */
.size-card .size-glyph { font-weight: 800; line-height: 1; color: var(--text); }
.size-card[data-scale="0.85"] .size-glyph { font-size: 1.1rem; }
.size-card[data-scale="0.92"] .size-glyph { font-size: 1.3rem; }
.size-card[data-scale="1.00"] .size-glyph { font-size: 1.55rem; }
.size-card[data-scale="1.12"] .size-glyph { font-size: 1.8rem; }
.size-card[data-scale="1.25"] .size-glyph { font-size: 2.05rem; }
.size-card[data-scale="1.40"] .size-glyph { font-size: 2.3rem; }
.size-card .size-px { font-family: var(--font-num); font-weight: 800; font-size: .92rem; }
.size-card.active .size-glyph { color: var(--primary); }

/* ---------- receipt size glyphs (รูปกระดาษจำลอง) ---------- */
.rsize-glyph {
  display: block; border: 2px solid var(--text-faint); border-radius: 3px;
  background: repeating-linear-gradient(var(--surface-2) 0 3px, transparent 3px 6px);
  position: relative; margin-bottom: 2px;
}
.rsize-glyph::before {
  content: ''; position: absolute; left: 3px; right: 3px; top: 3px; height: 3px;
  background: var(--text-faint); border-radius: 1px;
}
.rsize-80 { width: 20px; height: 44px; }
.rsize-a5 { width: 34px; height: 44px; }
.rsize-a4 { width: 40px; height: 52px; }
.opt-card.active .rsize-glyph { border-color: var(--primary); }
.opt-card.active .rsize-glyph::before { background: var(--primary); }

/* การ์ดส่วนหัว/ท้าย ตอนเลือก 80mm = จาง + กดไม่ได้ */
#receiptTextCard.is-disabled { opacity: .55; }
#receiptTextCard.is-disabled textarea { background: var(--surface-2); cursor: not-allowed; }

/* preview box */
.preview-box {
  margin-top: 16px; padding: 16px 18px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface-2);
}
.preview-label { font-size: .72rem; font-weight: 800; letter-spacing: .4px; text-transform: uppercase; color: var(--text-faint); margin-bottom: 8px; }

/* theme color cards */
.theme-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; }
@media (max-width:880px){ .theme-grid{grid-template-columns:repeat(2,1fr)} }
@media (max-width:480px){ .theme-grid{grid-template-columns:1fr} }
.theme-card {
  appearance: none; cursor: pointer; font-family: inherit; padding: 0; overflow: hidden;
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius);
  transition: border-color .12s, transform .06s, box-shadow .12s;
}
.theme-card:hover { border-color: var(--swatch); }
.theme-card:active { transform: translateY(1px); }
.theme-card.active { border-color: var(--swatch); box-shadow: 0 0 0 3px color-mix(in srgb, var(--swatch) 25%, transparent); }
/* preview จำลอง UI จริง: rail(เมนู) + body(topbar+stat+card) */
.theme-preview { display: flex; height: 104px; background: #f0f0f2; }
.tp-rail {
  width: 30%; background: linear-gradient(165deg, var(--swatch), color-mix(in srgb, var(--swatch) 62%, #000));
  padding: 8px 7px; display: flex; flex-direction: column; gap: 5px;
}
.tp-logo { width: 16px; height: 16px; border-radius: 5px; background: rgba(255,255,255,.85); margin-bottom: 3px; }
.tp-nav { height: 6px; border-radius: 3px; background: rgba(255,255,255,.32); }
.tp-nav.active { background: rgba(255,255,255,.92); width: 90%; }
.tp-body { flex: 1; background: #fff; padding: 9px 9px; display: flex; flex-direction: column; gap: 6px; }
.tp-top { display: flex; align-items: center; gap: 6px; }
.tp-title { height: 7px; width: 42%; border-radius: 3px; background: #d4d4d8; }
.tp-avatar { margin-left: auto; width: 12px; height: 12px; border-radius: 4px; background: var(--swatch); }
.tp-stats { display: flex; gap: 6px; }
.tp-stat { flex: 1; height: 22px; border-radius: 5px; background: #eef0f2; border: 1px solid #e3e5e8; }
.tp-stat.accent { border-left: 3px solid var(--swatch); background: color-mix(in srgb, var(--swatch) 8%, #fff); }
.tp-card { border: 1px solid #e6e8ea; border-radius: 5px; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.tp-line { height: 5px; border-radius: 3px; background: color-mix(in srgb, var(--swatch) 28%, #e4e4e6); width: 72%; }
.tp-line.short { width: 46%; background: #e4e4e6; }
.theme-name { display: block; padding: 11px; font-weight: 700; font-size: .9rem; text-align: center; color: var(--text); }

/* font cards */
.font-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; }
@media (max-width:880px){ .font-grid{grid-template-columns:repeat(2,1fr)} }
@media (max-width:480px){ .font-grid{grid-template-columns:1fr} }
.font-card {
  appearance: none; cursor: pointer; font-family: inherit; text-align: left;
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius);
  padding: 16px 16px; display: flex; flex-direction: column; gap: 10px;
  transition: border-color .12s, background .12s;
}
.font-card:hover { border-color: var(--primary); background: var(--surface-2); }
.font-card.active { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-tint); }
.font-sample { font-size: 1.5rem; font-weight: 700; color: var(--text); line-height: 1.1; }
.font-sample-en { font-size: 1rem; font-weight: 500; color: var(--text-soft); }
.font-meta { display: flex; flex-direction: column; gap: 3px; }
.font-name { font-weight: 700; font-size: .92rem; }
.font-desc { font-size: .76rem; color: var(--text-faint); background: var(--surface-2); align-self: flex-start; padding: 1px 8px; border-radius: 6px; }
.font-card.active .font-desc { background: var(--primary-tint); color: var(--primary); }

/* icon style cards */
.icon-card { padding: 0; overflow: hidden; gap: 0; }
.icon-card-head { width: 100%; padding: 9px 0; font-weight: 700; font-size: .92rem; background: var(--surface-2); display: flex; align-items: center; justify-content: center; gap: 7px; }
.icon-card-tag { font-family: var(--font-num); font-size: .72rem; font-weight: 700; color: var(--text-faint); background: var(--surface-3); padding: 1px 7px; border-radius: 6px; }
.icon-card-row { display: flex; gap: 9px; padding: 16px 8px; flex-wrap: wrap; justify-content: center; }
.icon-card-row i.fi { font-size: 1.35rem; color: var(--primary); }
.icon-card .status-text { padding: 0 0 12px; }
.icon-card.active { background: var(--primary-tint); }
.icon-card.active .icon-card-head { background: var(--primary); color: var(--primary-ink); }
.icon-card.active .icon-card-head .icon-card-tag { color: var(--primary); background: #fff; }
.icon-card.active .status-text { color: var(--primary); font-weight: 700; }

/* ============ TOGGLE SWITCH + SWITCH CARD ============ */
.switch-card {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 18px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.switch-card-info { flex: 1; min-width: 0; }
.switch-card-title { font-weight: 800; font-size: 1rem; }
.switch-card-desc { font-size: .82rem; color: var(--text-soft); margin-top: 3px; }
/* แสดงข้อความตามสถานะสวิตช์ */
.switch-card-desc .when-on { display: none; }
.switch-card.on .switch-card-desc .when-on { display: block; }
.switch-card.on .switch-card-desc .when-off { display: none; }

.switch { position: relative; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  display: block; width: 56px; height: 32px; border-radius: 999px;
  background: var(--border-strong); transition: background .18s; position: relative;
}
.switch-thumb {
  position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35); transition: transform .18s;
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(24px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 4px var(--primary-tint); }

/* mini-switch (ใช้ในตาราง — toggle เปิด/ปิดรับซื้อ) */
.mini-switch { position: relative; display: inline-flex; cursor: pointer; vertical-align: middle; }
.mini-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.mini-track { display: block; width: 40px; height: 23px; border-radius: 999px; background: var(--border-strong); transition: background .16s; position: relative; }
.mini-thumb { position: absolute; top: 2.5px; left: 2.5px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .16s; }
.mini-switch input:checked + .mini-track { background: var(--success); }
.mini-switch input:checked + .mini-track .mini-thumb { transform: translateX(17px); }
.mini-switch input:focus-visible + .mini-track { box-shadow: 0 0 0 3px var(--primary-tint); }

/* ปุ่มดินสอแก้ชื่อชนิดยาง (inline ในตารางราคา) */
.btn-rename {
  border: 0; background: transparent; cursor: pointer; color: var(--text-faint);
  padding: 3px; margin-left: 4px; border-radius: 6px; line-height: 1;
  vertical-align: middle; opacity: 0; transition: opacity .12s, color .12s, background .12s;
}
.btn-rename i.fi { font-size: .9rem; }
tr:hover .btn-rename { opacity: 1; }
.btn-rename:hover { color: var(--primary); background: var(--primary-tint); }
.btn-rename:focus-visible { opacity: 1; outline: 2px solid var(--primary); }
@media (hover: none) { .btn-rename { opacity: 1; } }  /* แท็บเล็ต: แสดงตลอด */

/* ซ่อน scale config เมื่อปิดเครื่องชั่ง */
#scaleConfigBox { transition: opacity .15s; }
#scaleConfigBox.disabled { display: none; }

/* ============ PRINT (ใบเสร็จ) ============ */
@media print {
  .sidebar, .topbar, .toast-wrap, .no-print { display: none !important; }
  .content { padding: 0; max-width: none; }
  body { background: #fff; }
  .card { box-shadow: none; border: none; }
}

/* ============ อัพเดทระบบ (settings) ============ */
.badge.blue   { background: color-mix(in srgb, #1971c2 16%, var(--surface)); color: #1971c2; }
.badge.purple { background: color-mix(in srgb, #7048e8 16%, var(--surface)); color: #7048e8; }

.update-version { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.uv-now { display: flex; flex-direction: column; gap: 2px; }
.uv-label { font-size: .8rem; color: var(--text-faint); font-weight: 600; }
.uv-num { font-family: var(--font-num); font-size: 1.8rem; font-weight: 800; line-height: 1; letter-spacing: -.5px; }
.uv-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.update-result { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.upd-new-head { font-weight: 800; margin-bottom: 10px; }
.upd-item { padding: 10px 0; border-bottom: 1px dashed var(--border); }
.upd-item:last-child { border-bottom: none; }
.upd-item-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.upd-date { font-size: .78rem; color: var(--text-faint); }
.upd-item-label { font-weight: 600; margin: 4px 0; }
.upd-notes { margin: 4px 0 0 18px; font-size: .88rem; color: var(--text-soft); }
.upd-notes li { margin: 2px 0; }

.changelog { display: flex; flex-direction: column; gap: 16px; }
.cl-version { border-left: 3px solid var(--primary); padding-left: 14px; }
.cl-head { display: flex; align-items: baseline; gap: 10px; }
.cl-ver { font-family: var(--font-num); font-weight: 800; font-size: 1.1rem; color: var(--primary); }
.cl-date { font-size: .78rem; color: var(--text-faint); }
.cl-label { font-weight: 600; margin: 4px 0 8px; }
.cl-changes { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 7px; }
.cl-changes li { font-size: .9rem; line-height: 1.5; display: flex; gap: 8px; align-items: flex-start; }
.cl-changes li .badge { flex: none; margin-top: 1px; }
@media (max-width: 560px) {
  .update-version { align-items: flex-start; }
  .uv-actions { width: 100%; }
  .uv-actions .btn { flex: 1; }
}

/* ============ RESPONSIVE: เลย์เอาต์ 2 คอลัมน์ที่ stack บนจอแคบ ============ */
/* ใช้แทน inline style grid-template-columns เพื่อให้ media query มีผล */
.split-2 { display: grid; grid-template-columns: 1.1fr 1fr; gap: calc(var(--space) + 6px); }
@media (max-width: 900px) {
  .split-2 { grid-template-columns: 1fr; }   /* แท็บเล็ตแนวตั้ง/มือถือ: วางซ้อนกัน */
}

/* polish จอเล็ก (มือถือ) — ลดระยะขอบ + ย่อหัวข้อให้พอดี */
@media (max-width: 640px) {
  .content { padding: 14px 12px; }
  .topbar { padding: 10px 14px; gap: 10px; }
  .page-head h1 { font-size: 1.28rem; }
  .card { padding: 16px 14px; }
  .modal-body { padding: 18px 16px; }
  .filter-bar { gap: 10px; }
  .filter-field, .filter-field input, .filter-field select, .filter-field .ts-wrapper { width: 100%; min-width: 0; }
}
/* จอเล็กมาก — ปุ่มเต็มความกว้างใน action bar */
@media (max-width: 420px) {
  .page-head { gap: 8px; }
  .page-head .btn { flex: 1; }
}

/* ============ Update Server URL — input group สวยงาม ============ */
.url-field { display: flex; align-items: center; gap: 10px; max-width: 680px; }
.url-input-wrap { position: relative; flex: 1; min-width: 0; }
.url-input-wrap i.fi {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--text-faint); font-size: 1rem; pointer-events: none;
}
.url-input-wrap input {
  width: 100%; padding-left: 40px !important;
  font-family: var(--font-num); letter-spacing: .1px;
}
.url-input-wrap input:focus + i.fi, .url-input-wrap:focus-within i.fi { color: var(--primary); }
.url-field .btn { white-space: nowrap; flex: none; }
/* code ในคำอธิบาย — ดูเป็นโค้ดอ่านง่าย */
.hint code {
  font-family: var(--font-num); font-size: .85em;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 5px; color: var(--text-soft);
}
@media (max-width: 560px) {
  .url-field { flex-direction: column; align-items: stretch; }
  .url-field .btn { width: 100%; }
}

/* ============ FIX: กัน grid item ดันความกว้างเกินจอ (min-width:auto) ============ */
/* grid item ที่มีตาราง/เนื้อหากว้าง จะดัน track ล้นจอ — บังคับให้ย่อได้ แล้วให้ .table-wrap เลื่อนเองภายใน */
.grid > *, .split-2 > * { min-width: 0; }
.table-wrap { max-width: 100%; }
/* การ์ดไม่ให้ล้นกรอบแม่ (ไม่ใส่ overflow-wrap:anywhere — มันตัดคำปกติทีละตัวอักษร เช่น a/d/m/i/n) */
.card { max-width: 100%; }
/* มือถือ: ตารางหลายคอลัมน์คงความกว้างอ่านง่าย แล้วเลื่อนแนวนอนใน .table-wrap แทนการบีบจนข้อความตก */
@media (max-width: 720px) {
  .table-wrap table.data { min-width: 560px; }
}

/* ============ คู่มือการใช้งาน (help.php) ============ */
.manual { display: grid; grid-template-columns: 250px 1fr; gap: var(--space); align-items: start; }
.manual-toc { position: sticky; top: 76px; }
.manual-toc #manualSearch { width: 100%; margin-bottom: 12px; }
.manual-toc nav { display: flex; flex-direction: column; gap: 2px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; max-height: calc(100vh - 160px); overflow-y: auto; }
.manual-toc-link {
  display: block; padding: 8px 11px; border-radius: var(--radius-sm);
  color: var(--text-soft); font-weight: 600; font-size: .9rem; line-height: 1.35;
  border-left: 3px solid transparent; transition: background .12s, color .12s, border-color .12s;
}
.manual-toc-link:hover { background: var(--surface-2); color: var(--text); }
.manual-toc-link.active { background: var(--primary-tint); color: var(--primary); border-left-color: var(--primary); }

.manual-body { min-width: 0; display: flex; flex-direction: column; gap: var(--space); }
.manual-section {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px 26px; scroll-margin-top: 80px;
}
.manual-section h2 { font-size: 1.25rem; display: flex; align-items: center; gap: 10px; margin: 0 0 12px; color: var(--text); }
.manual-section h2 i.fi { color: var(--primary); }
.manual-section h3 { font-size: 1rem; margin: 18px 0 8px; color: var(--text); }
.manual-section p { margin: 0 0 10px; color: var(--text-soft); }
.manual-section strong { color: var(--text); }

.manual-steps { margin: 6px 0 10px; padding-left: 22px; counter-reset: step; list-style: none; }
.manual-steps > li { position: relative; padding: 4px 0 8px 8px; color: var(--text-soft); line-height: 1.6; }
.manual-steps > li::before {
  counter-increment: step; content: counter(step); position: absolute; left: -22px; top: 4px;
  width: 22px; height: 22px; border-radius: 50%; background: var(--primary); color: var(--primary-ink, #fff);
  display: grid; place-items: center; font-size: .76rem; font-weight: 800; font-family: var(--font-num);
}
.manual-list { margin: 4px 0 10px; padding-left: 20px; }
.manual-list li { margin: 4px 0; color: var(--text-soft); line-height: 1.6; }

.manual-note {
  display: flex; gap: 11px; align-items: flex-start;
  background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--text-faint);
  border-radius: var(--radius-sm); padding: 12px 14px; margin: 12px 0; font-size: .92rem; color: var(--text-soft);
}
.manual-note i.fi { color: var(--text-faint); margin-top: 2px; flex: none; }
.manual-note.tip { border-left-color: var(--primary); background: var(--primary-tint); }
.manual-note.tip i.fi { color: var(--primary); }

.manual-faq dt { font-weight: 700; color: var(--text); margin-top: 14px; }
.manual-faq dt:first-child { margin-top: 0; }
.manual-faq dd { margin: 4px 0 0; padding-left: 14px; border-left: 2px solid var(--border); color: var(--text-soft); line-height: 1.6; }
.manual-foot { margin-top: 4px; text-align: center; font-size: .85rem; }

@media (max-width: 860px) {
  .manual { grid-template-columns: 1fr; }
  .manual-toc { position: static; top: auto; }
  .manual-toc nav { max-height: 240px; }
}
