/* =============================================================================
   Components — reusable UI building blocks used across many pages.
   Theme-agnostic: colors come from tokens.css custom properties.
   ============================================================================= */

/* -- Elevation / motion utilities -- */
.elev-1 { box-shadow: var(--elevation-1); }
.elev-2 { box-shadow: var(--elevation-2); }
.elev-3 { box-shadow: var(--elevation-3); }
.surface-sheen { background-image: var(--surface-sheen); }

button, .btn, .widget-card, .modal .modal-content, .signin-panel, .sb-item, .sb-toggle { transition: transform var(--transition-ui), box-shadow var(--transition-ui), background-color var(--transition-ui); }
.widget-card, .btn-primary, .btn { will-change: transform, box-shadow; }
.widget-card:hover { transform: translateY(-4px); box-shadow: var(--elevation-2); }
.btn:hover { transform: translateY(-1px); box-shadow: var(--elevation-1); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 18px rgba(16,42,67,0.12); }
.topbar { box-shadow: var(--elevation-topbar); }
.sidebar { box-shadow: 2px 0 12px rgba(16,42,67,0.03); }
.data-area { box-shadow: var(--elevation-1); border-radius: 4px; overflow: hidden; }
.modal .modal-content { box-shadow: var(--elevation-3); }


/* -- Topbar / Sidebar -- */
/* TOPBAR */
.topbar { display: flex; align-items: center; height: var(--topbar-height); min-height: var(--topbar-height); background: var(--topbar-bg); color: var(--topbar-text); padding: 0 var(--space-6); z-index: 100; flex-shrink: 0; }
.topbar-brand { display: flex; align-items: center; gap: var(--space-5); margin-right: var(--space-10); white-space: nowrap; }
.topbar-brand svg { flex-shrink: 0; }
/* The mark had no rule at all, so it painted at whatever the file happened to
   be - which worked only while that file was exactly 32x32. Swapping in a
   sharper 192px source put a six-times-too-big logo across the sidebar. The
   bar decides the size now, not the asset. */
.topbar-logo { width: 24px; height: 24px; object-fit: contain; flex-shrink: 0; }
.topbar-brand span { font-size: var(--font-size-base); font-weight: 600; letter-spacing: .3px; color: var(--color-text-white); }
.topbar-brand i { color: var(--color-text-white); font-size:14px; display:inline-block; }
.topbar-divider { width: 1px; height: 18px; background: var(--color-border-medium); margin: 0 var(--space-6); }
.topbar-module { font-size: var(--font-size-md); color: var(--color-dark-text-dim); white-space: nowrap; }
.topbar-search { margin-left: var(--space-16); position: relative; flex: 0 1 280px; }
.topbar-search input, .topbar-search .form-control { width: 100%; height: var(--btn-height); border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: var(--color-bg-white); color: var(--color-text-muted); font-size: var(--font-size-md); padding: 0 var(--space-5) 0 24px; outline: none; }
.topbar-search input::placeholder, .topbar-search .form-control::placeholder { color: var(--color-text-muted); }
.topbar-search input:focus, .topbar-search .form-control:focus { border-color: var(--color-link); background: var(--color-bg-header); box-shadow: none; }
.topbar-search > svg, .topbar-search > i { position: absolute; left: var(--space-5); top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--color-text-muted); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-1); }

/* -- Global Search Results Dropdown -- */
.global-search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 2000;
  max-height: 400px;
  overflow-y: auto;
  background: var(--color-bg-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--elevation-3);
  padding: var(--space-4) 0;
  animation: gsrFadeIn .12s ease-out;
}

@keyframes gsrFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.gsr-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: var(--space-5) var(--space-10) var(--space-3);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
.gsr-group:not(:first-child) { margin-top: var(--space-3); border-top: 1px solid var(--color-border-light); padding-top: var(--space-6); }
.gsr-group i { font-size: 10px; }

.gsr-item {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  padding: var(--space-5) var(--space-10);
  text-decoration: none;
  color: var(--color-text-primary);
  border-left: 2px solid transparent;
  transition: background-color .1s ease;
}
.gsr-item:hover, .gsr-item.active {
  background: var(--color-row-hover);
  border-left-color: var(--color-primary);
  color: var(--color-text-primary);
  text-decoration: none;
}

.gsr-item-icon {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  background: rgba(16, 42, 67, 0.08);
  color: var(--color-primary);
}
.gsr-item-icon.gsr-icon-page   { background: rgba(59, 130, 246, 0.12); color: var(--color-secondary); }
.gsr-item-icon.gsr-icon-record { background: rgba(30, 126, 30, 0.10); color: var(--color-status-active-fg); }

.gsr-item-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.gsr-item-title { font-size: var(--font-size-md); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gsr-item-title mark { background: rgba(244, 196, 48, 0.35); color: inherit; border-radius: 2px; padding: 0 1px; }
.gsr-item-sub { font-size: var(--font-size-xs); color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.gsr-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
  padding: var(--space-16) var(--space-10);
  color: var(--color-text-muted);
  font-size: var(--font-size-md);
  text-align: center;
}
.gsr-empty i { font-size: 20px; opacity: .4; }

/* -- App Launcher Dropdown --
   เมนูนี้เป็นทางเข้าของ "แอป" ที่พาออกไปทั้งหน้า (เครื่องหน้าร้าน จอในลาน) ไม่ใช่รายการเมนูธรรมดา
   ของเดิมเป็นตัวหนังสือเล็ก ๆ กับวงกลมสีจาง ๆ บนพื้นขาว - เจ้าของงาน 2026-09-09: "ไม่สวยไม่เด่น"
   ที่แก้: การ์ดมีขอบ/พื้นของตัวเองทุกใบ (ไม่ใช่โผล่ตอน hover) · ไอคอนเป็นสี่เหลี่ยมมนใหญ่ขึ้นและ
   ทึบขึ้นตอน hover · ป้ายสองบรรทัดตัดท้ายด้วย ... จึงสูงเท่ากันทุกใบ ไม่ฟันหลอเวลาชื่อไทยยาว ·
   หัวข้อกลุ่มมีเส้นคาดต่อท้าย · ใบที่เปิดคนละแท็บมีลูกศร ↗ มุมบน คนจะได้รู้ก่อนกด */
.app-launcher-menu {
  width: 372px;
  max-width: calc(100vw - 24px);
  padding: var(--space-10);
  border-radius: var(--radius-lg);
  box-shadow: var(--elevation-3);
  /* ธีมมืดตั้งพื้นของ dropdown บนแถบบนเป็นกระจกโปร่ง (--color-dark-surface = rgba(13,24,42,.82))
     ถ้าไม่เบลอ ตัวเลขบนหน้าหลังจะทะลุขึ้นมาอ่านปนกับชื่อแอป - ฝั่งสว่างพื้นทึบอยู่แล้ว ไม่กระทบ */
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.app-launcher-title {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--color-text-muted);
  padding: 0 var(--space-2) var(--space-6);
}
/* เส้นคาดต่อท้ายหัวข้อ - แยกกลุ่ม "เมนูลัด" ออกจาก "แอป" โดยไม่ต้องมี <hr> ในมาร์กอัป */
.app-launcher-title::after { content: ""; flex: 1 1 auto; height: 1px; background: var(--color-border); }
.app-launcher-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-6); }

/* กลุ่มที่มีไม่กี่รายการ (เมนูลัด) เป็นแถวเต็มความกว้าง: ไอคอนซ้าย ชื่อขวา อ่านเร็วกว่าและไม่เหลือช่องว่าง
   ที่ทำให้แผงดูโหรงเหรง · การ์ดสามช่องเก็บไว้ให้กลุ่ม "แอป" ที่พาออกไปคนละแท็บ */
.app-launcher-list { grid-template-columns: 1fr; gap: var(--space-4); }
.app-launcher-list .app-launcher-tile {
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  min-height: 0;
  gap: var(--space-8);
  padding: var(--space-6) var(--space-8);
}
.app-launcher-list .app-launcher-icon { width: 32px; height: 32px; font-size: 14px; flex: 0 0 auto; }
.app-launcher-list .app-launcher-label { -webkit-line-clamp: 1; text-align: left; flex: 1 1 auto; }


/* Accent color template picker (topbar, next to the theme toggle) - reuses
   .color-swatch (wachi-pickers.js toolkit, already themed for both light and
   dark) rather than a bespoke swatch style; Wachi.UI.applyPalette() in
   wachi-ui.js builds/colors #paletteGrid's children. */
.palette-menu { min-width: 220px; padding: var(--space-8); }
.palette-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--space-6); justify-items: center; }

.app-launcher-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-6);
  min-height: 92px;
  padding: var(--space-10) var(--space-4) var(--space-8);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-light);
  /* ไล่สีจาง ๆ ตามโทนของใบ - แต่ละแอปมีสีประจำตัวตั้งแต่ยังไม่ hover ไม่ใช่กล่องเทาเหมือนกันหมด */
  background: linear-gradient(180deg, rgba(var(--tile-accent-rgb, var(--color-primary-rgb)), .06), rgba(var(--tile-accent-rgb, var(--color-primary-rgb)), 0) 70%), var(--color-bg-surface);
  text-decoration: none;
  color: var(--color-text-secondary);
  transition: background-color var(--transition-ui), border-color var(--transition-ui),
              transform var(--transition-ui), box-shadow var(--transition-ui);
}
.app-launcher-tile:hover {
  background: var(--color-bg-white);
  border-color: rgba(var(--tile-accent-rgb, var(--color-primary-rgb)), .35);
  color: var(--color-text-primary);
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: var(--elevation-2);
}
.app-launcher-tile:active { transform: translateY(0); box-shadow: var(--elevation-1); }
.app-launcher-tile:focus-visible { outline: 2px solid rgba(var(--tile-accent-rgb, var(--color-primary-rgb)), .5); outline-offset: 2px; }

/* ใบที่เปิดคนละแท็บ (แอปแยก) บอกไว้ตั้งแต่ก่อนกด - ลูกศรตัวอักษรธรรมดา ไม่ผูกกับฟอนต์ไอคอน */
.app-launcher-tile[target="_blank"]::after {
  content: "\2197";
  position: absolute;
  top: var(--space-4);
  right: var(--space-5);
  font-size: 9px;
  line-height: 1;
  color: var(--color-text-muted);
  opacity: .45;
}
.app-launcher-tile[target="_blank"]:hover::after { opacity: .9; color: rgb(var(--tile-accent-rgb, var(--color-primary-rgb))); }

.app-launcher-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  background: rgba(var(--tile-accent-rgb, var(--color-primary-rgb)), .12);
  color: rgb(var(--tile-accent-rgb, var(--color-primary-rgb)));
  box-shadow: inset 0 0 0 1px rgba(var(--tile-accent-rgb, var(--color-primary-rgb)), .16);
  transition: background-color var(--transition-ui), color var(--transition-ui), box-shadow var(--transition-ui);
}
/* hover = ไอคอนทึบ ตัวอักษรขาว - นี่คือสิ่งที่ทำให้เมนูดูมีชีวิต ไม่ใช่วงกลมจาง ๆ ทั้งแผง */
.app-launcher-tile:hover .app-launcher-icon {
  background: rgb(var(--tile-accent-rgb, var(--color-primary-rgb)));
  color: var(--color-text-white);
  box-shadow: 0 6px 14px rgba(var(--tile-accent-rgb, var(--color-primary-rgb)), .35);
}

/* โทนสีต่อใบ - ประกาศเป็น "r, g, b" เพื่อให้ทั้งพื้นจาง เส้นขอบ เงา และสถานะ hover
   คำนวณจากค่าเดียว (tokens.css: ทุก tint ต้องสร้างจาก --*-rgb ไม่ใช่ rgba() ตายตัว) */
.app-launcher-icon-danger  { --tile-accent-rgb: 196, 43, 28; }
.app-launcher-icon-success { --tile-accent-rgb: 30, 126, 30; }
.app-launcher-icon-info    { --tile-accent-rgb: 59, 130, 246; }
.app-launcher-icon-warning { --tile-accent-rgb: 179, 134, 0; }

.app-launcher-label {
  display: -webkit-box;
  -webkit-line-clamp: 2;      /* ชื่อไทยยาว ๆ ("เครื่องหน้าร้านโรงอาหาร") ตัดที่สองบรรทัด ทุกใบสูงเท่ากัน */
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: var(--font-size-sm);
  font-weight: 600;
  text-align: center;
  line-height: 1.3;
}

.app-launcher-empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
  padding: var(--space-16) var(--space-8);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-size: var(--font-size-md);
  text-align: center;
}
.app-launcher-empty i { font-size: 20px; opacity: .4; }

/* -- Notification Bell -- */
.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: var(--radius-full);
  background: var(--color-status-inactive-fg);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  line-height: 15px;
  text-align: center;
}

.notif-menu {
  width: min(420px, calc(100vw - 1.25rem));
  max-width: 480px;
  min-width: 0;
  padding: 0;
  overflow: hidden;
}
.notif-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-10) var(--space-12);
  border-bottom: 1px solid var(--color-border-light);
  font-size: var(--font-size-lg);
  font-weight: 700;
  color: var(--color-text-primary);
}
.notif-mark-all {
  border: none;
  background: none;
  padding: 0;
  font-size: var(--font-size-xs);
  font-weight: 500;
  color: var(--color-primary);
  cursor: pointer;
}
.notif-mark-all:hover { text-decoration: underline; }

.notif-list {
  max-height: 440px;
  overflow-y: auto;
}

.notif-item {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--space-10);
  padding: var(--space-10) var(--space-12);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background-color .1s ease;
}
/* an item that opens its document is an <a> - it must still read as a row, not a link */
a.notif-item, a.notif-item:hover { color: inherit; text-decoration: none; }
.notif-item:hover { background: var(--color-row-hover); }
.notif-item.unread { background: rgba(16, 42, 67, 0.04); border-left-color: var(--color-primary); }

.notif-item-icon {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  margin-top: 1px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  background: rgba(16, 42, 67, 0.08);
  color: var(--color-primary);
}
.notif-item-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.notif-item-text {
  font-size: var(--font-size-lg);
  color: var(--color-text-primary);
  line-height: 1.4;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.notif-item.unread .notif-item-text { font-weight: 600; }
.notif-item-time { font-size: var(--font-size-xs); color: var(--color-text-muted); }
.notif-item-dot { flex: 0 0 auto; width: 7px; height: 7px; margin-top: 6px; border-radius: 50%; background: var(--color-primary); }

.notif-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
  padding: var(--space-16) var(--space-10);
  color: var(--color-text-muted);
  font-size: var(--font-size-md);
  text-align: center;
}
.notif-empty i { font-size: 20px; opacity: .4; }

/* Windows alerts on/off, under the list */
.notif-menu-footer {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  padding: var(--space-8) var(--space-12);
  border-top: 1px solid var(--color-border-light);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}
.notif-menu-footer[hidden] { display: none; }
.notif-desktop-hint { line-height: 1.4; }

@media (max-width: 575.98px) {
  .topbar {
    padding: 0 .5rem;
  }

  .topbar-module,
  .topbar-search,
  .language-dropdown,
  .company-dropdown,
  .topbar .d-sm-flex {
    display: none !important;
  }

  .topbar-actions {
    gap: .15rem;
    margin-left: auto;
  }

  .topbar-btn {
    width: 28px;
    height: 28px;
  }

  .notif-menu {
    width: min(320px, calc(100vw - 0.75rem));
    max-width: calc(100vw - 0.75rem);
    margin-right: 0.25rem;
  }

  .notif-menu-header {
    padding: .7rem .8rem;
    font-size: .8rem;
  }

  .notif-mark-all {
    font-size: .68rem;
  }

  .notif-item {
    gap: .6rem;
    padding: .75rem .8rem;
  }

  .notif-item-icon {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .notif-item-text {
    font-size: .82rem;
  }

  .notif-item-time {
    font-size: .68rem;
  }

  .notif-list {
    max-height: 320px;
  }
}

/* -- Announcement Popup (minimal, content/image-forward)
   Fully self-contained overlay - deliberately does NOT reuse Bootstrap's
   .modal/.modal-dialog/.modal-content classes or bootstrap.Modal JS, since
   those kept losing a cascade fight against something else in this stylesheet
   and ended up mispositioned. Zero shared class names = zero conflict. -- */
.ann-overlay {
  position: fixed;
  inset: 0;
  z-index: 10600;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-8);
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity .15s ease;
}
.ann-overlay.show { display: flex; opacity: 1; }

.ann-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 560px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 90px);
  background: var(--color-bg-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--elevation-3);
  overflow: hidden;
  animation: annCardPop .2s cubic-bezier(.34, 1.56, .64, 1);
}

@keyframes annCardPop {
  from { opacity: 0; transform: scale(.97) translateY(6px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* Type accent: a thin rail at the very top, one flat token color per
   type (the old 5px multi-color gradient read as decoration from a
   different decade). */
.ann-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--color-secondary);
  z-index: 4;
}
.ann-card[data-type="WARNING"]::before { background: var(--color-status-pending-fg); }
.ann-card[data-type="URGENT"]::before  { background: var(--color-status-inactive-fg); }

/* -- Header: icon + title + type badge + close, inside the card -- */
.ann-modal-header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-8);
  padding: var(--space-12) var(--space-12) var(--space-8);
  border-bottom: 1px solid var(--color-border-light);
}
.ann-modal-icon {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-header);
  color: var(--color-secondary);
  font-size: var(--icon-size);
}
.ann-card[data-type="WARNING"] .ann-modal-icon { color: var(--color-warning-strong); }
.ann-card[data-type="URGENT"] .ann-modal-icon { color: var(--color-status-inactive-fg); }
.ann-modal-heading {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-3);
}
.ann-modal-title {
  font-size: var(--font-size-title);
  font-weight: 600;
  color: var(--color-text-primary);
  line-height: 1.35;
}
.ann-modal-close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition-ui);
}
.ann-modal-close:hover {
  background: var(--color-row-hover);
  color: var(--color-text-primary);
}

.ann-badge {
  padding: 2px var(--space-6);
  border-radius: 999px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  letter-spacing: .2px;
  color: #fff;
}
.ann-badge-warning { background: var(--color-warning-strong); }
.ann-badge-urgent  { background: var(--color-status-inactive-fg); }

.ann-modal-body {
  position: relative;
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-10) var(--space-12);
  font-size: var(--font-size-lg);
  line-height: 1.7;
  color: var(--color-text-primary);
}
.ann-modal-body img { display: block; max-width: 100%; margin: var(--space-8) auto; border-radius: var(--radius-md); }
.ann-modal-body p:first-child { margin-top: 0; }
.ann-modal-body p:last-child { margin-bottom: 0; }

/* -- Footer: inside the card, on its own surface -- */
.ann-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-8);
  padding: var(--space-8) var(--space-12);
  border-top: 1px solid var(--color-border-light);
  background: var(--color-bg-surface);
}
.ann-modal-footer-actions {
  display: inline-flex;
  align-items: center;
  gap: var(--space-8);
  margin-left: auto;
}
.ann-modal-progress { font-size: var(--font-size-xs); color: var(--color-text-muted); }
.ann-modal-link {
  border: none;
  background: none;
  padding: var(--space-3) var(--space-5);
  font-size: var(--font-size-md);
  color: var(--color-text-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition-ui);
}
.ann-modal-link:hover {
  color: var(--color-text-primary);
  background: var(--color-row-hover);
}

.topbar-btn { display: flex; align-items: center; justify-content: center; width: 30px; height: 28px; background: none; border: none; color: var(--color-text-muted); cursor: pointer; border-radius: var(--radius-sm); }
.topbar-btn:hover { background: var(--color-dark-hover); color: var(--color-text-white); }
/* ปุ่มที่เปิด dropdown ค้างอยู่ต้องดูกดค้าง ไม่งั้นเมนูลอยมาโดยไม่รู้ว่ามาจากปุ่มไหน */
.topbar-btn[aria-expanded="true"] { background: var(--color-dark-active); color: var(--color-text-white); }
.topbar-btn i { font-size: 14px; }
.topbar-brand i, .topbar-btn i, .sb-header i, .sb-item i, .sb-sub-item i, .btn i { width: var(--icon-size); height: var(--icon-size); display: inline-flex; align-items: center; justify-content: center; }
.sb-item svg, .sb-header svg, .topbar-brand svg, .btn svg { width: var(--icon-size); height: var(--icon-size); }
.icon--sm { font-size: var(--icon-size-sm) !important; width: var(--icon-size-sm) !important; height: var(--icon-size-sm) !important; }
.icon--lg { font-size: var(--icon-size-lg) !important; width: var(--icon-size-lg) !important; height: var(--icon-size-lg) !important; }
.icon--xl { font-size: var(--icon-size-xl) !important; width: var(--icon-size-xl) !important; height: var(--icon-size-xl) !important; }
.icon--muted { color: var(--color-text-muted); }
.sb-icon { display: inline-flex; align-items: center; justify-content: center; text-align: center; }
.topbar-avatar { width: 22px; height: 22px; border-radius: var(--radius-full); background: var(--color-primary); color: var(--color-text-white); font-size: var(--font-size-xs); font-weight: 600; display: flex; align-items: center; justify-content: center; cursor: pointer; }

/* Topbar user dropdown tweaks */
.topbar .dropdown > .btn {
  padding: 0;
  display: inline-flex;
  align-items: center;
}
.topbar .dropdown > .btn {
  background: transparent;
  border: none;
  color: inherit;
}
.topbar .dropdown > .btn:hover {
  background: transparent;
}
.topbar .dropdown > .btn:focus {
  box-shadow: none;
}
/* The bar is --topbar-height tall, so nothing in it may be taller. This rule
   used to say 36px, which beat the avatar-xs the markup asks for and stood
   2px proud of the bar at the top and the bottom. 24px leaves an even 4px
   above and below - the same air the rest of the bar is laid out on. */
.topbar .topbar-avatar {
  width: 24px;
  height: 24px;
  font-size: 11px;
  font-weight: 700;
}
.topbar .dropdown .dropdown-menu {
  min-width: 200px;
}
.topbar .d-sm-flex { line-height: 1; }

/* ensure label text blends on dark topbar */
.topbar .d-sm-flex span { color: var(--color-text-white); }
.topbar .d-sm-flex .text-muted { color: rgba(255,255,255,0.75); }

/* dropdown menu styling to match app */
.topbar .dropdown .dropdown-menu {
  background: var(--color-bg-white);
  border: 1px solid var(--color-border);
  padding: 0.25rem 0;
}

/* dark theme menu */

/* SIDEBAR */
.sidebar { width: var(--sidebar-width); min-width: var(--sidebar-width); background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; overflow: hidden; flex-shrink: 0; border-right: 1px solid var(--color-border); }
.sb-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; }
.sb-collapse { display: flex; align-items: center; justify-content: flex-end; padding: var(--space-2) var(--space-3); }
.sb-collapse .topbar-btn { width: 28px; height: 28px; }
.sidebar { transition: width 200ms ease, min-width 200ms ease; }
/* Whole-sidebar icon-only mode - same single-source-of-truth attribute approach
   as the section collapse above, for the same reason (avoids a flash of the
   full-width sidebar before wachi-ui.js would otherwise apply a class). */
html[data-sidebar-collapsed] .sidebar { width: var(--sidebar-collapsed-width); min-width: var(--sidebar-collapsed-width); }
html[data-sidebar-collapsed] .sb-label { display: none; }
html[data-sidebar-collapsed] .sb-item { justify-content: center; padding: var(--space-2); margin: 0 var(--space-3); }
html[data-sidebar-collapsed] .sb-sub-item { justify-content: center; padding: var(--space-1); }
html[data-sidebar-collapsed] .sb-header { justify-content: center; }
html[data-sidebar-collapsed] .sb-collapse i { transform: rotate(180deg); }
.sb-group { display: block; }
.sb-toggle { display: flex; align-items: center; gap: var(--space-5); width: 100%; background: none; border: none; text-align: left; padding: var(--space-2) var(--space-6); cursor: pointer; color: inherit; }
.sb-toggle .sb-chevron { margin-left: auto; transition: transform 180ms ease; font-size: var(--icon-size-sm); transform: rotate(90deg); }
.sb-children { overflow: hidden; max-height: 2000px; transition: max-height 200ms ease; }
.sb-children .sb-sub-item { padding-left: calc(var(--space-6) + var(--space-6)); }

/* Sidebar section collapse - single source of truth is the html[data-sb-collapsed]
   attribute (a space-separated list of section ids), never a class on the section
   itself. It's written synchronously in theme-init.js before the sidebar even
   parses (so the very first paint is already correct - no JS handoff, no race),
   and kept up to date in-place by wachi-ui.js on every toggle click afterwards. */
html[data-sb-collapsed~="favorites"] .sb-group[data-section-id="favorites"] .sb-children,
html[data-sb-collapsed~="modules"] .sb-group[data-section-id="modules"] .sb-children {
  max-height: 0;
}
html[data-sb-collapsed~="favorites"] .sb-group[data-section-id="favorites"] .sb-chevron,
html[data-sb-collapsed~="modules"] .sb-group[data-section-id="modules"] .sb-chevron {
  transform: none;
}
html[data-sidebar-collapsed] .sb-children { display: none !important; }
html[data-sidebar-collapsed] .sb-chevron { display: none !important; }
.sb-section { border-bottom: 1px solid var(--color-dark-border); }
.sb-section:last-child { border-bottom: none; }
.sb-header { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-4) var(--space-6) var(--space-3); font-size: var(--font-size-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--color-text-muted); cursor: pointer; user-select: none; }
.sb-header:hover { color: var(--color-text-light); }
.sb-header svg, .sb-header i { flex-shrink: 0; }
/* Rounded, inset rows with a tinted active pill. Margin + padding put the
   label at the same x as the old 3px-border layout, and the row height is
   unchanged - the density stays what UI_UX_RULES §10.5 fixes. */
.sb-item { display: flex; align-items: center; gap: var(--space-5); margin: 0 var(--space-5); padding: var(--space-2) var(--space-6) var(--space-2) 11px; font-size: var(--font-size-lg); color: var(--color-text-secondary); cursor: pointer; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; border-radius: var(--radius-sm); text-decoration: none; }
.sb-item:hover { background: rgba(var(--color-primary-rgb), .05); color: var(--color-text-primary); }
.sb-item.active { background: rgba(var(--color-primary-rgb), .09); color: var(--color-primary); font-weight: 600; }
.sb-item svg, .sb-item i { flex-shrink: 0; opacity: .85; width: 18px; text-align: center; }
.sb-item:hover svg, .sb-item:hover i, .sb-item.active svg, .sb-item.active i { opacity: 1; }
.sb-sub-item { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-1) var(--space-6) var(--space-1) 30px; font-size: var(--font-size-md); color: var(--color-text-muted); cursor: pointer; white-space: nowrap; }
.sb-sub-item:hover { color: var(--color-text-primary); background: var(--color-bg-surface); }

/* SIDEBAR FAVORITES */
.sb-fav-btn { display: none; background: none; border: none; padding: 2px 4px; cursor: pointer; color: var(--color-text-muted); font-size: 9px; line-height: 1; border-radius: 3px; transition: all 0.15s ease; flex-shrink: 0; }
.sb-item:hover .sb-fav-btn { display: inline-flex; }
.sb-fav-btn:hover { color: #f59e0b; background: rgba(245, 158, 11, 0.15); }
.sb-fav-btn.is-favorite { display: inline-flex; color: #f59e0b; }
.sb-fav-btn.is-favorite i { font-weight: 900; }
.sb-fav-btn.is-favorite:hover { color: #ef4444; background: rgba(239, 68, 68, 0.15); }
.sb-favorites { background: rgba(245, 158, 11, 0.05); }
.sb-favorites .sb-header { color: #f59e0b; }
.sb-favorites .sb-item { padding-right: var(--space-6); }
.sb-favorites .sb-fav-btn { display: inline-flex; color: #f59e0b; }
.sb-favorites .sb-fav-btn:hover { color: #ef4444; }
html[data-sidebar-collapsed] .sb-fav-btn { display: none !important; }

/* -- Page header (breadcrumb, title row, cmd/page/tab bars) -- */
/* PAGE HEADER */
.page-breadcrumb { font-size: var(--font-size-md); color: var(--color-text-light); display: flex; align-items: center; gap: var(--space-2); }
.page-breadcrumb span { color: var(--color-text-muted); }
.page-breadcrumb a { color: var(--color-link); text-decoration: none; }
.page-breadcrumb a:hover { text-decoration: underline; }
.page-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: var(--title-row-height);
  padding: 0 var(--space-6);
  background: var(--pagebar-bg);
  border-bottom: 1px solid var(--pagebar-border);
  flex-shrink: 0;
}
.page-title-row__title {
  flex: 1 1 auto;
  min-width: 0;
}
.page-title-row__title h1,
.page-title-row__title h4 {
  font-size: var(--font-size-title);
  font-weight: 600;
  color: var(--color-text-primary);
  margin: 0;
  line-height: 1.2;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.page-title-row__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-left: auto;
}
.page-title-row__actions > * {
  flex-shrink: 0;
}
/* White like the title row above it, so the page head reads as one surface
   instead of stacked grey stripes; the hairline below still splits the rows. */
.cmd-bar { display: flex; align-items: center; gap: 1px; height: var(--cmd-bar-height); min-height: var(--cmd-bar-height); padding: 0 var(--space-5); background: var(--color-bg-white); border-bottom: 1px solid var(--color-border-light); flex-shrink: 0; }

@media (max-width: 767.98px) {
  .page-title-row {
    flex-wrap: wrap;
    align-items: flex-start;
    padding: .8rem .85rem;
    gap: .6rem;
  }

  .page-title-row__title,
  .page-title-row__actions {
    width: 100%;
    flex-basis: 100%;
  }

  .page-title-row__actions {
    justify-content: flex-start;
    margin-left: 0;
  }

  .page-title-row__actions > * {
    flex: 1 1 auto;
    min-width: 0;
  }

  .page-title-row__actions .btn,
  .page-title-row__actions .cmd-btn,
  .page-title-row__actions a,
  .page-title-row__actions button {
    width: auto;
    max-width: 100%;
    white-space: normal;
    text-align: left;
    justify-content: flex-start;
    padding-top: .45rem;
    padding-bottom: .45rem;
    min-height: 34px;
    line-height: 1.3;
  }
}
.cmd-sep { width: 1px; height: 16px; background: var(--color-border-medium); margin: 0 var(--space-2); }
.page-bar { display: flex; align-items: center; gap: var(--space-5); height: var(--page-bar-height); min-height: var(--page-bar-height); padding: 0 var(--space-6); background: var(--pagebar-bg); border-bottom: 1px solid var(--pagebar-border); flex-shrink: 0; }
.tab-bar { display: flex; align-items: center; height: var(--tab-bar-height); min-height: var(--tab-bar-height); padding: 0 var(--space-5); background: var(--color-bg-white); border-bottom: 1px solid var(--color-border-light); flex-shrink: 0; overflow-x: auto; overflow-y: hidden; }
/* Thinner horizontal bar - the tab strip is only 36px tall. */
.tab-bar::-webkit-scrollbar { height: 6px; }
.tab-item { display: inline-flex; flex-shrink: 0; align-items: center; height: 24px; padding: 0 var(--space-8); font-size: var(--font-size-md); color: var(--color-text-secondary); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; text-decoration: none; }
.tab-item:hover { color: var(--color-text-primary); background: var(--color-bg-surface); }
.tab-item.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 600; }


/* -- Buttons -- */
/* BUTTONS */
.btn { display: inline-flex; align-items: center; gap: var(--space-3); height: var(--btn-height); padding: 0 var(--space-6); border: 1px solid var(--color-border-input); border-radius: var(--radius-sm); background: var(--color-bg-surface); color: var(--color-text-primary); font-size: var(--font-size-md); cursor: pointer; white-space: nowrap; line-height: 1; transition: transform 0.15s ease, box-shadow 0.15s ease; }
.btn:hover { background: var(--color-bg-surface); border-color: var(--color-border-input); color: var(--color-text-primary); }
.btn svg { flex-shrink: 0; }
.btn i { flex-shrink: 0; margin-right: 6px; }
.btn-primary, .btn.btn-primary { background: var(--color-primary) !important; color: var(--color-text-white) !important; border-color: var(--color-primary) !important; }
.btn-primary:hover, .btn.btn-primary:hover { background: var(--color-primary-hover) !important; }
.btn-danger, .btn.btn-danger { background: var(--color-status-inactive-fg) !important; color: var(--color-text-white) !important; border-color: var(--color-status-inactive-fg) !important; }
.btn-danger:hover, .btn.btn-danger:hover { background: var(--color-status-inactive-bg) !important; color: var(--color-text-primary) !important; border-color: var(--color-status-inactive-fg) !important; }
.btn-outline-secondary { background: var(--color-bg-surface); color: var(--color-text-primary); border-color: var(--color-border-input); }
.btn-outline-secondary:hover { background: var(--color-bg-header); color: var(--color-text-primary); border-color: var(--color-border-input); }

/* ── ความหนาแน่นของฟอร์ม ──
   ป้ายชื่อช่องกับช่องกรอกเป็นของคู่กัน ระยะ 8px ระหว่างสองอันนี้กว้างกว่าระยะ
   ระหว่างช่องกับช่องข้าง ๆ เสียอีก - สายตาจึงจับกลุ่มผิด และหนึ่งแถวฟิลด์กินไป
   51px ทั้งที่ตัวหนังสือสูงแค่ 19 · บีบสองระยะนี้ได้ ~10px ต่อแถวฟิลด์ โดยไม่แตะ
   ขนาดตัวอักษรเลย (mb-3 ของ Bootstrap เป็น utility ที่มี !important จึงต้องทับด้วย
   !important และจำกัดขอบเขตไว้เฉพาะในฟอร์ม ไม่ใช่ทั้งเว็บ) */
.form-label { margin-bottom: 2px; }

/* ── ป้ายกับค่าต้องเป็นคนละสี ──
   ป้ายชื่อช่องกับค่าในช่องเคยดำเท่ากัน (#111 ทั้งคู่) มองผ่าน ๆ แยกไม่ออกว่าอะไรคือ
   คำถามอะไรคือคำตอบ ป้ายเป็นเทาอ่านออก (--color-text-muted = 4.7:1 บนพื้นขาว)
   ค่ายังดำเข้มเหมือนเดิม - สายตาจะกระโดดไปหาค่าเอง เพราะค่าคือสิ่งที่คนเปิดหน้ามาดู
   .form-check-label (ป้ายข้างสวิตช์/checkbox) เป็นป้ายเหมือนกัน จึงสีเดียวกัน */
.form-label, .form-check-label { color: var(--color-text-muted); }

/* ── grid 24 ช่องสำหรับช่องฟอร์ม (.fcol-N) ──
   Bootstrap มี 12 ช่อง: col-1 แคบเกินใส่วันที่ col-2 กว้างเกินสำหรับวันที่ ครึ่งช่องคือ
   คำตอบ - .fcol-N คือ N/24 ของแถว ใช้ร่วมกับ .row ของ Bootstrap ตามปกติ และเส้น
   ทุกเส้นของ 12 ช่องเดิมก็เป็นเส้นของ 24 ช่องอยู่แล้ว หน้าที่เขียน col-lg-* เองจึง
   ยังเรียงตรงกับช่องที่ component เลือกให้ · ทำงานที่ ≥ lg เท่านั้น ต่ำกว่านั้น
   col-12 / col-md-6 ที่ติดมาด้วยรับช่วงต่อ (components.php: Utils_fieldCols) */
@media (min-width: 992px) {
  .row > .fcol-2  { flex: 0 0 auto; width: 8.333333%; }
  .row > .fcol-3  { flex: 0 0 auto; width: 12.5%; }
  .row > .fcol-4  { flex: 0 0 auto; width: 16.666667%; }
  .row > .fcol-6  { flex: 0 0 auto; width: 25%; }
  .row > .fcol-8  { flex: 0 0 auto; width: 33.333333%; }
  .row > .fcol-12 { flex: 0 0 auto; width: 50%; }
}

/* ในแผง offcanvas (~600px) N/24 ของแถวเล็กเกินจะกรอกอะไรได้ (fcol-2 = 50px) - แมปเป็นครึ่งแผง/เต็มแผง
   ช่องสั้นในแผงจึงไม่ต้องส่ง 'col' มาทับเหมือนกับหน้าเต็มจอ (UI_UX_RULES ความกว้างของช่องในฟอร์ม 2026-09-09) */
@media (min-width: 992px) {
  .offcanvas .row > .fcol-2, .offcanvas .row > .fcol-3, .offcanvas .row > .fcol-4, .offcanvas .row > .fcol-6 { width: 50%; }
  .offcanvas .row > .fcol-8, .offcanvas .row > .fcol-12 { width: 100%; }
}

/* ── สวิตช์/checkbox ที่อยู่แถวเดียวกับช่องที่มีป้าย ──
   ช่องอื่นมีป้าย (16.5px + 2px) แล้วค่อยเป็นช่อง (26.5px) แต่ .form-check ไม่มีป้ายด้านบน
   จึงลอยขึ้นไปอยู่ระดับป้ายของเพื่อนบ้าน - ดันลงมาให้สวิตช์อยู่กึ่งกลางระดับเดียวกับช่อง
   จับเฉพาะแถวที่มีเพื่อนบ้านแบบมีป้ายจริง ๆ ในแผง offcanvas ที่เรียงทีละช่องไม่เข้ากฎนี้ */
.pane-body form .row:has(> [class*="col-"] > .form-label) > [class*="col-"] > .form-check:first-child {
  margin-top: 18.5px;
  min-height: 26.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 0;       /* flex ไม่ใช้ float ของ Bootstrap แล้ว - ระยะระหว่างสวิตช์กับป้ายมาจาก gap */
}
.pane-body form .row:has(> [class*="col-"] > .form-label) > [class*="col-"] > .form-check:first-child > .form-check-input { margin: 0; float: none; flex: none; }
/* ── ช่องที่มีไอคอน: กรอบต้องครอบไอคอนด้วย ──
   ช่องวันที่ (renderFormGroupInput) ag-select และ tree-select ประกอบจาก .input-group
   ที่ addon ถูกถอดขอบทิ้ง ไอคอนจึงลอยอยู่นอกกรอบของช่อง อ่านเป็นสองชิ้นที่วางชิดกัน
   ไม่ใช่ช่องเดียว - ย้ายขอบไปไว้ที่ตัวกลุ่มแล้วถอดขอบชิ้นในออกทั้งหมด addon ไม่มีพื้น
   ให้เหมือน caret ของ <select> ธรรมดาที่อยู่ในกรอบเดียวกับค่า

   จับเฉพาะกลุ่มที่มีช่องฟอร์ม (.form-underline) - ตัวกรองบน command bar ก็เป็น
   .input-group แต่ใช้ addon แบบมีพื้นของ Bootstrap อยู่แล้วและมีกฎ .filter-active
   ของตัวเอง ไม่แตะ · ช่องข้างในเสียขอบ 1px ไป กลุ่มได้ 1px คืน ความสูงจึงเท่าเดิม
   สีตอน focus ลอกจาก .form-control:focus ของ Bootstrap เพื่อให้ช่องมีไอคอนกับ
   ช่องไม่มีไอคอน focus แล้วหน้าตาเหมือนกันเป๊ะ */
.input-group:has(> .form-control.form-underline) {
  flex-wrap: nowrap;
  border: 1px solid var(--color-border-input);
  border-radius: var(--radius-sm);
  background: var(--color-bg-white);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input-group:has(> .form-control.form-underline):focus-within {
  border-color: #86b7fe;
  box-shadow: 0 0 0 .25rem rgba(13, 110, 253, .25);
}
.input-group:has(> .form-control.form-underline) > .form-control,
.input-group:has(> .form-control.form-underline) > .form-control:focus {
  border: 0;
  background: transparent;
  box-shadow: none;
  border-radius: 0;
}
.input-group:has(> .form-control.form-underline) > .input-group-text,
.input-group:has(> .form-control.form-underline) > .btn {
  border: 0;
  background: transparent;
  color: var(--color-text-muted);
  padding: 0 8px;
  border-radius: 0;
}
.input-group:has(> .form-control.form-underline) > .btn:hover { color: var(--color-text-primary); }.pane-body [class*="col-"].mb-3,
.offcanvas-body [class*="col-"].mb-3 { margin-bottom: .5rem !important; }

/* ── ค่าที่อ่านอย่างเดียวบนหน้า _details (`renderFormReadonly`) ──
   น้ำหนักบรรทุก เวลาออก เวลาถึง วันที่สร้าง ไม่ใช่ช่องกรอก แต่ถูก render เป็น
   <input disabled> เพราะนั่นคือ component ที่มีอยู่ กล่องเทา ๆ ห้าใบเรียงกัน
   อ่านว่า "ฟอร์มที่พังอยู่" มากกว่า "ข้อเท็จจริงของเอกสารใบนี้" - คลาสนี้ถอด
   กรอบกับพื้นออกให้เหลือแค่ตัวหนังสือ โดยยังเป็น input ที่ disabled อยู่เหมือนเดิม
   (ต้องเจาะจงกว่า .form-control:disabled ของ Bootstrap ไม่งั้นพื้นเทากลับมา)
   สูงเท่าช่องกรอกข้าง ๆ ด้วย เพื่อให้แถวที่ปนกันไม่เหลื่อม */
.form-readonly-value {
  min-height: var(--btn-height);
  padding-top: 3px;
  color: var(--color-text-primary);
  font-weight: 500;
  line-height: 1.35;
  word-break: break-word;
}
.form-readonly-value a { color: var(--color-primary); }

input.form-control.form-readonly,
input.form-control.form-readonly:disabled,
textarea.form-control.form-readonly:disabled {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  padding-left: 0;
  color: var(--color-text-primary);
  font-weight: 500;
}
.cmd-btn, .cmd-bar .btn-link { display: inline-flex; align-items: center; gap: var(--space-2); height: var(--btn-height); padding: 0 var(--space-5); border: none; background: none; color: var(--color-text-secondary); font-size: var(--font-size-md); cursor: pointer; border-radius: var(--radius-sm); text-decoration: none !important; }
.cmd-btn:hover, .cmd-bar .btn-link:hover { background: var(--color-bg-header); color: var(--color-text-primary); text-decoration: none !important; }
.cmd-btn svg { flex-shrink: 0; }
.cmd-btn i { margin-right: 6px; }

/* -- ตัวกรองที่มีค่าอยู่ (ตั้งโดย Wachi.Grid.bindFilterMemory) --
   ตัวกรองที่จำไว้ข้ามการเปิดหน้าคือสาเหตุคลาสสิกของ "ข้อมูลหายไปไหน" - คนกดเข้ามา
   เห็นไม่กี่แถวแล้วคิดว่าข้อมูลหาย ทั้งที่ตัวเองตั้งกรองไว้เมื่อชั่วโมงก่อน
   ขอบซ้ายหนา + พื้นจาง ๆ ทำให้ตอบตัวเองได้จากหน้าจอว่าช่องไหนกำลังกรองอยู่
   ไม่ได้พึ่งสีอย่างเดียว (ความหนาของขอบเห็นได้แม้แยกสีไม่ออก) */
.input-group.filter-active > .form-select,
.input-group.filter-active > .form-control,
.input-group.filter-active > .ts-wrapper { border-color: var(--color-primary); }
.input-group.filter-active > .input-group-text {
  border-color: var(--color-primary);
  border-left: 3px solid var(--color-primary);
  background: rgba(var(--color-primary-rgb), 0.08);
  color: var(--color-primary);
}

/* -- Password visibility toggle (used on signin + user offcanvas forms) -- */
.password-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
}


/* -- Data table / grid generic hooks -- */
/* DATA TABLE / AG GRID */
.data-area { flex: 1; overflow: hidden; background: var(--color-bg-white); padding: 0; }
.cell-link { color: var(--color-link); text-decoration: none; cursor: pointer; }
.cell-link:hover { text-decoration: underline; }
.cell-badge { display: inline-block; padding: 0 5px; height: 16px; line-height: 16px; font-size: var(--font-size-xs); font-weight: 600; border-radius: var(--radius-sm); }
.badge-active { background: var(--color-status-active-bg); color: var(--color-status-active-fg); }
.badge-inactive { background: var(--color-status-inactive-bg); color: var(--color-status-inactive-fg); }
.badge-pending { background: var(--color-status-pending-bg); color: var(--color-status-pending-fg); }


/* -- Status bar -- */
/* STATUS BAR */
.status-bar { display: flex; align-items: center; justify-content: space-between; height: var(--status-bar-height); min-height: var(--status-bar-height); padding: 0 var(--space-6); background: var(--color-bg-surface); border-top: 1px solid var(--color-border); font-size: var(--font-size-sm); color: var(--color-text-muted); flex-shrink: 0; }
.status-bar a { color: var(--color-link); text-decoration: none; font-size: var(--font-size-sm); }
.icon--brand { width: 16px; text-align: center; display: inline-block; }
.vr--18 { height: 18px; }
.min-h-200 { min-height: 200px; }
.app-error { padding: 32px; color: var(--color-danger, #c00); }


/* -- Modal -- */
/* MODAL */
.modal .modal-content { background: var(--color-bg-white); border-radius: var(--radius-sm); box-shadow: 0 4px 24px rgba(0,0,0,.25); min-width: 360px; max-width: 640px; font-family: var(--font-family); }
.modal .modal-header { padding: var(--space-6) var(--space-6); border-bottom: 1px solid var(--color-border); font-size: var(--font-size-title); font-weight: 600; }
.modal .modal-body { padding: var(--space-6); overflow-y: auto; font-size: var(--font-size-lg); }
.modal .modal-footer { justify-content: flex-end; gap: var(--space-5); padding: var(--space-5) var(--space-6); border-top: 1px solid var(--color-border); }
.modal .btn-close:hover { opacity: 1; }


/* -- Offcanvas / dashboard widget shell -- */
/* DASHBOARD WIDGETS */
.offcanvas { font-family: var(--font-family); font-size: var(--font-size-base); }
.offcanvas .offcanvas-header { padding: var(--space-6); border-bottom: 1px solid var(--color-border); }
.offcanvas .offcanvas-body { padding: var(--space-6); font-size: var(--font-size-lg); }
.offcanvas .offcanvas-footer { font-size: var(--font-size-sm); color: var(--color-text-muted); }

/* A modal opened from inside a panel: the panel's own number (1045) caps
   everything in it, while the modal's backdrop sits on <body> at 1050 and would
   otherwise grey out the modal it belongs to. Set by Wachi.UI.initUserPicker()
   for as long as such a modal is open. */
.offcanvas.offcanvas-modal-open { z-index: 1056; }
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-6); padding: var(--space-6); }
.widget-card { background: var(--color-bg-white); border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: var(--space-8); display: flex; flex-direction: column; gap: var(--space-3); }
.widget-card-title { font-size: var(--font-size-sm); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; color: var(--color-text-light); }
.widget-card-value { font-size: 22px; font-weight: 700; color: var(--color-text-primary); }
.widget-card-sub { font-size: var(--font-size-sm); color: var(--color-text-muted); }


/* -- Avatar component -- */
/* AVATAR COMPONENT */
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%; font-size: 13px; font-weight: 600; color: #fff; text-transform: uppercase; user-select: none; flex-shrink: 0; position: relative; }
.avatar-xs { width: 24px; height: 24px; font-size: 10px; }
/* รูปคนหน้าค่าในช่องอ่านอย่างเดียว (สร้างโดย/แก้ไขโดย) - 18px เตี้ยกว่าช่องกรอก 22px จึงไม่ดันแถว
   ต้องเป็น flex ไม่ใช่ inline: inline-block 18px บนบรรทัด 16px ยืดกล่องบรรทัดเป็น 25px ทันที */
.avatar-inline { width: 18px; height: 18px; font-size: 9px; object-fit: cover; flex: none; }
.form-readonly-value:has(> .avatar-inline) { display: flex; align-items: center; gap: 6px; padding-top: 0; }
.avatar-sm { width: 30px; height: 30px; font-size: 11px; }
.avatar-md { width: 40px; height: 40px; font-size: 14px; }
.avatar-lg { width: 48px; height: 48px; font-size: 16px; }
.avatar-xl { width: 64px; height: 64px; font-size: 20px; }
.avatar-2xl { width: 80px; height: 80px; font-size: 24px; }
.avatar-3xl { width: 96px; height: 96px; font-size: 32px; }
.fs-20 { font-size: 20px !important; }
.fs-24 { font-size: 24px !important; }
.fs-32 { font-size: 32px !important; }
.fs-40 { font-size: 40px !important; }
.avatar-xxs { width: 24px !important; height: 24px !important; font-size: 9px !important; }
.cursor-pointer { cursor: pointer !important; }
.w-200px { width: 200px !important; }
.h-100 { height: 100% !important; }
.f-10 { font-size: 10px !important; }
.w-45pct { width: 45% !important; }
.w-40px { width: 40px !important; }
.w-120px { width: 120px !important; }
.w-100px { width: 100px !important; }
.h-400px { height: 400px !important; }
.h-300px { height: 300px !important; }
.legend-color-completed { background: linear-gradient(135deg, var(--color-status-active-fg) 0%, #2da52d 100%); }
.legend-color-inprogress { background: linear-gradient(135deg, #0d6efd 0%, #3d8bfd 100%); }
.legend-color-pending { background: linear-gradient(135deg, #ffc107 0%, #ffcd39 100%); }
.legend-color-delayed { background: linear-gradient(135deg, #dc3545 0%, #e35d6a 100%); }
.legend-color-planned { background: linear-gradient(135deg, #6c757d 0%, #8c959d 100%); }
.avatar-primary { background-color: var(--color-primary); }
.avatar-secondary { background-color: var(--color-secondary); }
.avatar-success { background-color: var(--color-success); }
.avatar-danger { background-color: var(--color-danger); }
.avatar-warning { background-color: var(--color-warning); color: var(--color-text-primary); }
.avatar-info { background-color: var(--color-info); }
.avatar-dark { background-color: var(--color-dark); }
.avatar-light { background-color: var(--color-bg-surface); color: var(--color-text-primary); border: 1px solid var(--color-border); }
.avatar-square { border-radius: var(--radius-sm); }
.avatar-status::after { content: ''; position: absolute; bottom: 1px; right: 1px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--color-bg-white); background-color: var(--color-secondary); }
.avatar-status[data-status="online"]::after { background-color: var(--color-success); }
.avatar-status[data-status="busy"]::after { background-color: var(--color-danger); }
.avatar-status[data-status="away"]::after { background-color: var(--color-warning); }
.avatar-status[data-status="offline"]::after { background-color: var(--color-secondary); }
.avatar-group { display: inline-flex; flex-direction: row-reverse; }
.avatar-group .avatar { margin-left: -10px; border: 2px solid var(--color-bg-white); transition: transform var(--transition-ui); }
.avatar-group .avatar:last-child { margin-left: 0; }
.avatar-group .avatar:hover { transform: translateY(-2px); z-index: 1; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }

.avatar.user-avatar-preview {
  width: 100px !important;
  height: 100px !important;
  overflow: hidden;
  border: 2px solid #e0e0e0;
  font-size: 2.5rem !important;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50% !important;
}
.user-avatar-image {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  display: block;
}
.user-avatar-image.hidden {
  display: none !important;
}
.user-avatar-edit-label {
  bottom: -5px;
  right: -10px;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  padding: 6px 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.user-avatar-edit-label:hover {
  background: rgba(255, 255, 255, 0.9);
}

/* -- Delete button on gallery thumbnails (asset/product/tooling detail pages) --
   Hover-only: this is a DESTRUCTIVE action, and having a red circle
   stamped on every thumbnail made it the loudest element on the whole
   detail page, sitting exactly where the eye lands first. It now appears
   when the user is actually pointing at (or keyboard-focusing) that
   thumbnail. -- */
.delete-asset-image-btn {
  width: 16px;
  height: 16px;
  top: -5px;
  right: -5px;
  z-index: 2;
  padding: 0;
  border: 1.5px solid var(--color-bg-white);
  border-radius: 50%;
  background: var(--color-status-inactive-fg);
  color: #fff;
  font-size: 8px;
  line-height: 1;
  box-shadow: var(--elevation-1);
  opacity: 0;
  transform: scale(.85);
  pointer-events: none;
  transition: var(--transition-ui);
}
.position-relative:hover > .delete-asset-image-btn,
.delete-asset-image-btn:focus-visible {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}
.delete-asset-image-btn:hover {
  filter: brightness(.9);
  transform: scale(1.1);
}
.delete-asset-image-btn i {
  pointer-events: none;
}


/* -- Common page chrome (used by 20+ pages) -- */
/* --- Common Page Styles --- */
.main-scroll {
  overflow-y: auto;
  flex: 1;
}
.component-section {
  background: var(--color-bg-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.component-section h5 {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border-light);
}

/* -- Tables (generic) -- */
/* --- Tables Page --- */
.table { font-size: 12px; }
.table th { font-weight: 600; }
.action-btn {
  padding: 2px 6px;
  font-size: 11px;
}


/* -- Tom Select underline variant (kept for parity with the old
   .select2-underline form styling; original select carries the class,
   Tom Select copies it onto .ts-wrapper) -- */
.ts-wrapper.select2-underline .ts-control {
  border: none;
  border-bottom: 1px solid var(--color-border);
  border-radius: 0;
  background: transparent;
  padding-left: 0;
}
.ts-wrapper.select2-underline.focus .ts-control {
  border-color: var(--color-primary);
  box-shadow: 0 1px 0 0 var(--color-primary);
}


/* -- Summary card (used on 5 _details pages) -- */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.summary-card {
  background: var(--color-bg-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.summary-card .icon {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.summary-card .icon.primary { background: rgba(16, 42, 67, 0.1); color: var(--color-primary); }
.summary-card .icon.success { background: rgba(30, 126, 30, 0.1); color: var(--color-status-active-fg); }
.summary-card .icon.warning { background: rgba(255, 193, 7, 0.2); color: var(--color-warning-strong); }
.summary-card .icon.danger { background: rgba(196, 43, 28, 0.1); color: var(--color-status-inactive-fg); }
.summary-card .info h6 {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-muted);
  margin: 0 0 4px 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.summary-card .info .value {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text-primary);
}
.summary-card .info .change {
  font-size: 11px;
  margin-top: 4px;
}
.summary-card .info .change.up { color: var(--color-status-active-fg); }
.summary-card .info .change.down { color: var(--color-status-inactive-fg); }

/* -- Split pane / fast-tabs (used on 22 _details pages + role_details/directory_party) -- */
.split-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 1px;
  background: var(--color-border);
}
.left-pane {
  width: 380px;
  min-width: 280px;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
}
.right-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  overflow: hidden;
}
.pane-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface-alt);
  font-weight: 600;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.pane-header i {
  color: var(--color-primary);
}
.pane-body {
  flex: 1;
  overflow: auto;
}
/* jsTree hierarchy panels (Documentation topics, category/account/location trees) */
.tree-scroll {
}
.fast-tabs {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.fast-tab {
  border-bottom: 1px solid var(--color-border);
}
.fast-tab-header {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  background: var(--color-surface-alt);
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-size: 12px;
  gap: 8px;
  transition: background 0.15s;
}
.fast-tab-header:hover {
  background: var(--color-hover);
}
.fast-tab-header i.fa-chevron-down {
  margin-left: auto;
  font-size: 10px;
  transition: transform 0.2s;
}
.fast-tab.collapsed .fast-tab-header i.fa-chevron-down {
  transform: rotate(-90deg);
}
.fast-tab-content {
  padding-top: 0px;
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: 8px;
  background: var(--color-surface);
  display: block;
}
.fast-tab.collapsed .fast-tab-content {
  display: none;
}

/* -- User chip (used on ticket_details.html) -- */
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  font-size: 11px;
  margin: 2px;
}
.user-chip .avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 600;
}
.user-chip .remove {
  cursor: pointer;
  opacity: 0.5;
}
.user-chip .remove:hover {
  opacity: 1;
  color: var(--color-danger);
}

/* -- Pickers: color-swatch, dropzone, rating/quantity/dual-range/icon picker, flatpickr sizing --
   Live toolkit: wachi-pickers.js self-initializes on every page load, so this styles
   any input a page opts into via class, even though no current page markup uses it yet. */
/* Color Swatches */
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.active {
  border-color: var(--bs-primary);
  box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.3);
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--bs-border-color);
  border-radius: 8px;
  padding: 30px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--bs-primary);
  background-color: rgba(14, 165, 233, 0.05);
}

/* Rating Picker */
.rating-picker { display: inline-flex; align-items: center; }
.rating-star {
  font-size: 1.25rem;
  color: #d1d5db;
  cursor: pointer;
  transition: color 0.15s ease;
}
.rating-star:hover, .rating-star.active, .rating-star.hovered { color: #fbbf24; }

/* Quantity Picker */
.quantity-picker .qty-input {
  appearance: textfield;
  -moz-appearance: textfield;
}
.quantity-picker .qty-input::-webkit-outer-spin-button,
.quantity-picker .qty-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

/* Dual Range */
.dual-range-container { position: relative; height: 30px; }
.dual-range {
  position: absolute;
  width: 100%;
  pointer-events: none;
  background: transparent;
}
.dual-range::-webkit-slider-thumb { pointer-events: auto; }
.dual-range::-moz-range-thumb { pointer-events: auto; }

/* Icon Picker */
.icon-picker-dropdown { max-height: 200px; overflow-y: auto; }

/* Flatpickr Inline */
.flatpickr-inline-wrapper .flatpickr-calendar {
  box-shadow: none;
  border: 1px solid var(--bs-border-color);
}

/* Flatpickr Compact Size - width MUST be exactly 7 * .flatpickr-day's max-width
   (32px * 7 = 224px). The previous 260px left 36px of slack per row, which is
   >= one more 32px cell, so the browser's inline-block flow let an 8th day
   fit on the same line before wrapping - the grid silently rendered 8 columns
   instead of 7, so it no longer lined up with the 7-day-name header row above
   it (every date after the first row appeared shifted under the wrong
   weekday, even though the actual selected/stored Date value was always
   correct - only the visual grid was misaligned). Keep these four widths
   (.flatpickr-calendar, .flatpickr-calendar.hasTime, .flatpickr-days,
   .dayContainer) and .flatpickr-day's max-width in that same 7:1 ratio if
   either one changes. */
.flatpickr-calendar {
  font-size: 12px;
  width: 224px;
}
.flatpickr-calendar.hasTime { width: 224px; }
.flatpickr-months { height: 28px; }
.flatpickr-months .flatpickr-month { height: 28px; line-height: 1; }
.flatpickr-current-month { font-size: 12px; height: 28px; padding-top: 5px; }
.flatpickr-current-month input.cur-year { font-size: 12px; }
.flatpickr-months .flatpickr-prev-month,
.flatpickr-months .flatpickr-next-month { height: 28px; padding: 5px 8px; }
.flatpickr-months .flatpickr-prev-month svg,
.flatpickr-months .flatpickr-next-month svg { width: 12px; height: 12px; }
span.flatpickr-weekday { font-size: 11px; }
.flatpickr-day { height: 32px; line-height: 32px; max-width: 32px; }
.flatpickr-days { width: 224px; }
.dayContainer { width: 224px; min-width: 224px; max-width: 224px; }
.flatpickr-time { height: 36px; line-height: 36px; max-height: 36px; }
.flatpickr-time input { font-size: 12px; height: 30px; }
.flatpickr-time .flatpickr-am-pm { font-size: 11px; height: 30px; line-height: 30px; }
.flatpickr-time .flatpickr-time-separator { height: 30px; line-height: 30px; }

/* File Item */
.file-item {
  display: flex;
  align-items: center;
  padding: 0.5rem;
  background: var(--bs-tertiary-bg);
  border-radius: 4px;
  margin-bottom: 0.25rem;
}
.file-item i { margin-right: 0.5rem; }
.file-item .file-name {
  flex-grow: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-item .file-size {
  color: var(--bs-secondary-color);
  font-size: 0.75rem;
  margin-left: 0.5rem;
}


/* -- Form editors: Quill / CodeMirror / Markdown preview --
   Live toolkit: wachi-editor.js self-initializes on every page load (same pattern as pickers). */
/* Quill Snow Theme Adjustments */
.ql-toolbar.ql-snow {
  border-top-left-radius: 0.375rem;
  border-top-right-radius: 0.375rem;
  border-color: var(--bs-border-color);
  background: var(--bs-tertiary-bg);
  padding: 0.1rem;
}
.ql-container.ql-snow {
  border-bottom-left-radius: 0.375rem;
  border-bottom-right-radius: 0.375rem;
  border-color: var(--bs-border-color);
  font-family: inherit;
  font-size: 0.9rem;
}
/* Quill ships `height: 100%` on both .ql-container and .ql-editor. Inside a
   Bootstrap .row - which is display:flex - the column holding the editor is
   a stretched flex item, so that percentage stops resolving to auto and
   starts resolving against a height the flex line settled before the editor
   had grown. The container then measures short while .ql-editor keeps the
   height its min-height demands, the column never grows to cover it, and the
   editor is painted straight through whatever comes next - the attachment
   dropzone, in the add-ticket panel at rows: 25.

   Both go back to auto, so the box is measured from what is in it. Quill's
   overflow-y: auto stays and now only bites once an editor is given a real
   height of its own. */
.ql-container.ql-snow,
.ql-container.ql-snow .ql-editor {
  height: auto;
}
/* renderFormQuillEditor()'s `rows` sets this; 150px is the floor for any
   editor that does not ask. The container above it grows to match, so an
   editor can never be taller than the box it is drawn in. */
.ql-editor {
  min-height: var(--wachi-quill-min-height, 150px);
}
.ql-editor.ql-blank::before {
  color: var(--bs-secondary-color);
  font-style: normal;
}

/* Quill Bubble Theme */
.ql-bubble .ql-editor {
  padding: 0;
}
.ql-bubble .ql-tooltip {
  z-index: 1060;
}

/* CodeMirror Container */
.CodeMirror {
  height: 280px !important;
  border: 1px solid var(--bs-border-color);
  border-radius: 0.375rem;
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
}
.CodeMirror-gutters {
  border-radius: 0.375rem 0 0 0.375rem;
}

/* Markdown Preview */
.markdown-preview {
  background: var(--bs-body-bg);
  font-size: 0.9rem;
  line-height: 1.7;
}
.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4,
.markdown-preview h5,
.markdown-preview h6 {
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  font-weight: 600;
}
.markdown-preview h1 { font-size: 1.5rem; }
.markdown-preview h2 { font-size: 1.25rem; border-bottom: 1px solid var(--bs-border-color); padding-bottom: 0.25rem; }
.markdown-preview h3 { font-size: 1.1rem; }
.markdown-preview pre {
  padding: 0.75rem;
  border-radius: 0.375rem;
  overflow-x: auto;
}
.markdown-preview code {
  background: var(--bs-tertiary-bg);
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-size: 0.85em;
}
.markdown-preview pre code {
  background: transparent;
  padding: 0;
}
.markdown-preview blockquote {
  border-left: 4px solid var(--bs-primary);
  padding-left: 1rem;
  margin-left: 0;
  color: var(--bs-secondary-color);
}
.markdown-preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
}
.markdown-preview th,
.markdown-preview td {
  border: 1px solid var(--bs-border-color);
  padding: 0.5rem;
  text-align: left;
}
.markdown-preview th {
  font-weight: 600;
}
.markdown-preview ul,
.markdown-preview ol {
  padding-left: 1.5rem;
}
.markdown-preview a {
  color: var(--bs-primary);
}

/* CodeMirror Light Theme Adjustments */
.CodeMirror {
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
}
.CodeMirror-gutters {
  background: var(--bs-tertiary-bg);
  border-color: var(--bs-border-color);
}
.CodeMirror-linenumber {
  color: var(--bs-secondary-color);
}

/* -- Color picker field (renderFormColor) -- */
.wachi-color-field { display: flex; align-items: center; gap: var(--space-6); }
.wachi-color-field .wachi-color-swatch {
  width: 40px;
  height: 40px;
  padding: 2px;
  border: 1px solid var(--color-border-input);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
  background: none;
}
.wachi-color-field .wachi-color-swatch::-webkit-color-swatch-wrapper { padding: 2px; }
.wachi-color-field .wachi-color-swatch::-webkit-color-swatch { border: none; border-radius: var(--radius-sm); }
.wachi-color-field .wachi-color-swatch::-moz-color-swatch { border: none; border-radius: var(--radius-sm); }
.wachi-color-field .wachi-color-hex {
  max-width: 110px;
  font-family: var(--font-mono);
  text-transform: uppercase;
}
.wachi-color-presets { display: flex; flex-wrap: wrap; gap: var(--space-6); margin-top: var(--space-6); }
.wachi-color-preset {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  border: 2px solid var(--color-bg-white);
  outline: 1px solid var(--color-border-input);
  cursor: pointer;
  padding: 0;
  transition: transform .1s ease;
}
.wachi-color-preset:hover { transform: scale(1.15); }
.wachi-color-preset.is-selected { outline: 2px solid var(--color-link); outline-offset: 1px; }

/* -- Schedule calendar attendee tooltip (bootstrap.Popover content) --
   Sizing lives here, not as inline style="...", because Popover's default
   sanitizer strips style attributes even with html: true - see
   schedule_calendar.js's buildAttendeeTooltipHtml(). */
.schedule-attendee-tooltip { max-width: 320px; }
.schedule-attendee-tooltip-item { width: 80px; }
.schedule-attendee-tooltip-avatar {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-full);
  object-fit: cover;
  border: 1px solid var(--color-border-input);
}
.schedule-attendee-tooltip-name { max-width: 80px; font-size: 12px; }

/* -- AI Chatbot page (template/pages/system_administration/ai_chatbot/) -- */
.chatbot-messages { display: flex; flex-direction: column; gap: var(--space-10); padding: var(--space-10) 0; }
.chatbot-bubble-row { display: flex; align-items: flex-end; gap: var(--space-8); }
.chatbot-bubble-row.chatbot-row-user { justify-content: flex-end; }
.chatbot-bubble-row.chatbot-row-bot { justify-content: flex-start; }
.chatbot-bubble-row.chatbot-row-system { justify-content: center; }
.chatbot-bubble {
  max-width: 70%;
  padding: var(--space-8) var(--space-10);
  border-radius: var(--radius-md);
  font-size: var(--font-size-md);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.chatbot-bubble-user { background: var(--color-secondary); color: var(--color-text-white); border-bottom-right-radius: 2px; }
.chatbot-bubble-bot { background: var(--color-bg-header); color: var(--color-text-primary); border: 1px solid var(--color-border); border-bottom-left-radius: 2px; }
.chatbot-bubble-system { background: transparent; color: var(--color-text-muted); font-size: var(--font-size-xs); font-style: italic; max-width: 90%; text-align: center; }
.chatbot-bubble.is-thinking { opacity: .65; }
.chatbot-input-row textarea { resize: none; max-height: 120px; }

.chatbot-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  object-fit: cover;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
}
.chatbot-avatar-user.chatbot-avatar-initial {
  background: var(--color-secondary);
  color: var(--color-text-white);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  user-select: none;
}
.chatbot-avatar-bot {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  font-size: 14px;
}

.chatbot-layout { display: flex; overflow: hidden; position: relative; }
.chatbot-main { flex: 1 1 auto; min-width: 0; }

.chatbot-quick-panel {
  width: 300px;
  flex-shrink: 0;
  border-left: 1px solid var(--color-border);
  background: var(--color-bg-header);
}
.chatbot-quick-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-10) var(--space-10) var(--space-6);
}
.chatbot-quick-panel-title { font-size: var(--font-size-sm); font-weight: 600; color: var(--color-text-primary); }
.chatbot-quick-panel-search { position: relative; padding: 0 var(--space-10) var(--space-8); }
.chatbot-quick-panel-search i { position: absolute; left: calc(var(--space-10) + 10px); top: 50%; transform: translateY(-50%); color: var(--color-text-muted); font-size: 12px; }
.chatbot-quick-panel-search input { padding-left: 28px; }
.chatbot-quick-tree { padding: 0 var(--space-6) var(--space-10); }
.chatbot-quick-tree .jstree-anchor { font-size: var(--font-size-sm); }

.chatbot-quick-panel-expand-btn {
  position: absolute;
  right: 0;
  top: 140px;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  border: 1px solid var(--color-border);
  border-right: none;
  background: var(--color-bg-header);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.chatbot-quick-panel-expand-btn:hover { color: var(--color-text-primary); }


/* ==========================================
   DataTables child-row control - suppress DataTables' built-in triangle
   so the dashboard tables can use the app's FontAwesome chevrons instead
   (see non_conformances.js / production_yield_rate_dashboards.js).
   ========================================== */
table.dataTable td.dt-control::before {
  display: none !important;
}
table.dataTable td.dt-control {
  cursor: pointer;
}

/* DataTables auto-detects date-typed columns and right-aligns them -
   dates should read left-aligned like the rest of the app's text
   (numeric columns keep their explicit .text-end). */
table.dataTable td.dt-type-date,
table.dataTable th.dt-type-date {
  text-align: left;
}

/* Sticky header for every DataTable that sits in the page scroller.
   The seven live dashboards (non_conformances, vendor_claim_dashboards,
   production_*_dashboards, product_margin_dashboard) render DataTables
   inside .main-scroll and scroll the whole page, so a long table loses
   its column names by the second screen. The list pages are AG Grid,
   which scrolls inside its own viewport and keeps its header anyway.
   Sticky resolves against the nearest ancestor whose overflow is not
   visible, so two wrappers would swallow it: .widget-card (overflow:
   hidden for its rounded corners) and a .table-responsive box
   (overflow-x: auto). A card that holds a DataTable gives up the clip
   (the table brings its own margins, nothing bleeds); on wide screens
   the responsive box gives up its scroll box too, while narrow screens
   keep horizontal scrolling and lose the sticky header, the lesser
   evil. Same fix pm_plan_details.html made by hand on 2026-09-21 - now
   the rule is central, and qa/sticky_check.js measures it. */
.main-scroll table.dataTable > thead > tr > th,
.main-scroll table.dataTable > thead > tr > td {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--color-bg-white, #fff);
  box-shadow: inset 0 -1px 0 var(--color-border, #dee2e6);
}
.main-scroll .widget-card:has(table.dataTable) {
  overflow: visible;
}
@media (min-width: 992px) {
  .main-scroll .table-responsive:has(table.dataTable) {
    overflow: visible;
  }
}
/* Pagination (DataTables + any Bootstrap pagination) - follow the theme's
   primary token instead of Bootstrap's stock blue: navy in light mode,
   gold in dark mode (with the matching on-accent text color), both via
   tokens.css so theme switches apply automatically. */
.pagination {
  --bs-pagination-color: var(--color-primary);
  --bs-pagination-hover-color: var(--color-primary-hover);
  --bs-pagination-focus-color: var(--color-primary-hover);
  --bs-pagination-active-bg: var(--color-primary);
  --bs-pagination-active-border-color: var(--color-primary);
  --bs-pagination-active-color: var(--color-on-accent);
  --bs-pagination-focus-box-shadow: 0 0 0 0.2rem rgba(16, 42, 67, 0.15);
}
[data-theme="dark"] .pagination {
  --bs-pagination-focus-box-shadow: 0 0 0 0.2rem rgba(var(--color-primary-rgb), 0.2);
}

/* Excel-export icon (dashboard tables) - a bare floating icon in the
   theme's success/active green: no border, no background, just the
   icon; hover raises it on a soft round backdrop. */
.btn-export-excel {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  color: var(--color-status-active-fg);
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  transition: var(--transition-ui);
}
.btn-export-excel i {
  font-size: var(--icon-size-lg);
}
.btn-export-excel span {
  display: none;
}
.btn-export-excel:hover {
  color: var(--color-status-active-fg);
  background: var(--color-status-active-bg);
  box-shadow: var(--elevation-1);
  transform: translateY(-1px);
}
.btn-export-excel:active {
  transform: translateY(0);
  box-shadow: none;
}

/* Floating icon button - borderless icon-only action button used in
   widget headers (e.g. the Excel export on the dashboard lot tables).
   Sits flat until hover, then lifts with the theme's elevation shadow. */
.btn-float-icon {
  border: 0;
  background: transparent;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: var(--icon-size-lg);
  transition: var(--transition-ui);
  cursor: pointer;
}
.btn-float-icon:hover {
  color: var(--color-primary);
  background: var(--color-primary-bg, rgba(16, 42, 67, 0.08));
  transform: translateY(-1px);
  box-shadow: var(--elevation-1);
}
.btn-float-icon:active {
  transform: translateY(0);
  box-shadow: none;
}
[data-theme="dark"] .btn-float-icon:hover {
  background: rgba(var(--color-primary-rgb), 0.12);
}

/* ==========================================
   UI refresh (2026-08): segmented pill styling for quick-toggle button
   groups (date-range presets .range-btn + dashboard metric toggles
   .metric-btn). The active button still carries .btn-primary via the
   existing JS - this only restyles, no behavior change. Data density
   untouched: same heights, same footprint.
   ========================================== */
.btn-group:has(> .range-btn),
.btn-group:has(> .metric-btn) {
  background: var(--color-bg-header);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}
.btn-group > .range-btn,
.btn-group > .metric-btn {
  border: 0 !important;
  border-radius: 999px !important;
  background: transparent;
  color: var(--color-text-light);
  transition: var(--transition-ui);
}
.btn-group > .range-btn.btn-outline-secondary:hover,
.btn-group > .metric-btn.btn-outline-secondary:hover {
  background: var(--color-row-hover);
  color: var(--color-text-primary);
}
.btn-group > .range-btn.btn-primary,
.btn-group > .metric-btn.btn-primary {
  background: var(--color-primary);
  color: var(--color-on-accent);
  box-shadow: var(--elevation-1);
}

/* ==========================================
   Icon tone discipline (2026-08 UI refresh) - navigation chrome icons
   read as muted monochrome; color appears on hover/active (and stays
   reserved for icons that MEAN something: status badges, alerts,
   favorite stars - none of which these selectors touch). Overrides the
   per-module `text-warning`/`text-success` utility classes baked into
   the module registry icon strings, hence the !important (Bootstrap's
   text utilities are themselves !important).
   ========================================== */

/* Sidebar module list */
.sb-item .sb-icon {
  color: var(--color-text-muted) !important;
  transition: var(--transition-ui);
}
.sb-item:hover .sb-icon,
.sb-item.active .sb-icon {
  color: var(--color-primary) !important;
}

.swal2-toast.wachi-toast {
  border-radius: 14px !important;
  padding: .8rem 1rem !important;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18) !important;
  border: 1px solid rgba(148, 163, 184, 0.28) !important;
  background: rgba(255, 255, 255, 0.96) !important;
  backdrop-filter: blur(8px);
}

.swal2-toast.wachi-toast .swal2-title {
  font-size: .95rem;
  font-weight: 600;
  line-height: 1.5;
  margin: 0;
}

.swal2-toast.wachi-toast .swal2-html-container {
  margin-top: .2rem;
  font-size: .875rem;
  line-height: 1.4;
}

.swal2-toast.wachi-toast .swal2-icon {
  margin: 0 .7rem 0 0;
  width: 1.5rem;
  height: 1.5rem;
}

.swal2-toast.wachi-toast .swal2-icon-content {
  font-size: .9rem;
}

.swal2-toast.wachi-toast .swal2-timer-progress-bar {
  height: 4px;
  border-radius: 999px;
}

@media (max-width: 575.98px) {
  .swal2-toast.wachi-toast {
    left: .75rem !important;
    right: .75rem !important;
    width: auto !important;
    max-width: none !important;
    padding: .75rem .85rem !important;
    border-radius: 12px !important;
  }

  .swal2-toast.wachi-toast .swal2-title {
    font-size: .9rem;
  }

  .swal2-toast.wachi-toast .swal2-html-container {
    font-size: .82rem;
  }
}

/* ── Isometric solids (module header scene + tile icons) ──────────────────
   One colour at three opacities, all from --color-primary-rgb, so the whole
   set retints with whichever of the ten palettes the user picked and needs no
   dark-mode overrides: the same alphas read correctly on #ffffff and #0a1425.
   This is the reason the solid is SVG rather than a PNG per module.
   ───────────────────────────────────────────────────────────────────────── */
.iso-t  { fill: rgba(var(--color-primary-rgb), .26); }
.iso-r  { fill: rgba(var(--color-primary-rgb), .40); }
.iso-l  { fill: rgba(var(--color-primary-rgb), .56); }
.iso-sh { fill: rgba(var(--color-primary-rgb), .11); }

/* Header ------------------------------------------------------------------ */
.module-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 10px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg,
              rgba(var(--color-primary-rgb), .07),
              rgba(var(--color-primary-rgb), .015));
}

.module-head-main {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

/* The scene sits behind the module's own icon - the pile is decoration, the
   icon is what says which module this is. */
.module-head-icon {
  position: relative;
  flex: none;
  width: 92px;
  height: 78px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border-radius: 0;
}

.module-head-icon .iso-scene {
  position: absolute;
  inset: 0;
  width: 92px;
  height: 78px;
  overflow: visible;
}

/* Anchored to the top cube's own top face, not centred in the box.
   isoScene() puts that cube's top-face centre at (54, 18.5) of a 108x92
   viewBox - 50% across, 20% down - and the pile sits high in that box with
   the contact shadow below it, so centring the glyph in the container instead
   dropped it a whole icon-height too low and it read as sunk into the pile
   rather than standing on it. The -58% lifts it by a little over half its own
   height so it rests on the surface instead of straddling it. */
.module-head-icon > i {
  position: absolute;
  left: 50%;
  top: 20%;
  transform: translate(-50%, -58%);
  z-index: 2;
  font-size: 22px;
  color: var(--color-primary);
  filter: drop-shadow(0 4px 5px rgba(var(--color-primary-rgb), .35));
}

.module-head-text { min-width: 0; }

.module-head-text h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--color-text-primary);
}

.module-head-text p {
  margin: 2px 0 0;
  font-size: var(--font-size-md);
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* Count of what is on screen - renderModuleMenu() fills it after every render,
   so it follows the search filter rather than always reporting the full list. */
.module-head-count {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--color-bg-white);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  vertical-align: middle;
}

.module-head-tools { display: flex; align-items: center; gap: 6px; }

.module-search { position: relative; display: flex; align-items: center; }

.module-search > i {
  position: absolute;
  left: 10px;
  font-size: var(--icon-size-sm);
  color: var(--color-text-muted);
  pointer-events: none;
}

.module-search input {
  width: 230px;
  max-width: 100%;
  height: 30px;
  padding: 0 30px 0 28px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg-white);
  color: var(--color-text-primary);
  font-size: var(--font-size-md);
  font-family: inherit;
  transition: border-color .16s ease, box-shadow .16s ease;
}

.module-search input::placeholder { color: var(--color-text-muted); }

.module-search input:focus {
  outline: none;
  border-color: rgba(var(--color-primary-rgb), .55);
  box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), .12);
}

.module-search button {
  position: absolute;
  right: 6px;
  border: 0;
  background: transparent;
  color: var(--color-text-muted);
  line-height: 0;
  padding: 4px;
  border-radius: var(--radius-full);
  cursor: pointer;
}

.module-search button:hover { color: var(--color-text-primary); }

/* Grid -------------------------------------------------------------------- */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 10px;
  align-items: stretch;
}

.module-group-title {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 -4px;
  font-size: var(--font-size-sm);
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.module-group-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

.module-group-title:first-child { margin-top: 0; }

/* Tile -------------------------------------------------------------------- */
/* การ์ดแถวเดียว (2026-09-18): ไอคอน | ชื่อ + คำอธิบายบรรทัดเดียว | ตัวเลข - เดิมสูง ~170px
   หน้าไอที 19 การ์ดต้องเลื่อนสามจอ ตอนนี้ ~64px ทั้งโมดูลอยู่ในจอเดียว คำอธิบายเต็มอยู่ใน tooltip */
.module-grid .module-tile {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  min-height: 64px;
  min-width: 0; /* ชื่อ/คำอธิบายเป็นบรรทัดเดียว (nowrap) - ไม่มีบรรทัดนี้การ์ดจะดันคอลัมน์ให้กว้างตามข้อความบนจอมือถือ */
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  /* A wash of the accent from the top-left corner - the tint follows the
     palette rather than being a fixed pastel, which is what would break the
     moment somebody picked amber or crimson. */
  background: linear-gradient(160deg,
              rgba(var(--color-primary-rgb), .05),
              rgba(var(--color-primary-rgb), 0) 62%),
              var(--color-bg-white);
  box-shadow: var(--elevation-1);
  text-decoration: none;
  color: inherit;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}

.module-grid .module-tile:hover,
.module-grid .module-tile:focus-visible {
  transform: translateY(-2px);
  box-shadow: var(--elevation-2);
  border-color: rgba(var(--color-primary-rgb), .45);
  outline: none;
  color: inherit;
}

.module-grid .module-tile:focus-visible {
  box-shadow: var(--elevation-2), 0 0 0 3px rgba(var(--color-primary-rgb), .18);
}

.module-grid .module-tile-icon {
  position: relative;
  flex: none;
  width: 44px;
  height: 50px;
  /* ย่อทั้งกล่อง ไม่แก้ขนาดข้างใน - ตำแหน่งไอคอนบนหน้าลูกบาศก์คำนวณไว้ที่ 44x50 (ดูข้างล่าง)
     margin ติดลบคืนพื้นที่ที่ scale ไม่คืนให้ */
  transform: scale(.72);
  margin: -7px -6px;
  background: none;
  border-radius: 0;
  display: block;
  overflow: visible;
}

.module-grid .module-tile-icon .iso-svg {
  position: absolute;
  inset: 0;
  width: 44px;
  height: 50px;
  overflow: visible;
}

/* Upright, in front of the solid. Laying the glyph onto the isometric top face
   looks more three-dimensional and was tried first, but a clipboard and a
   warning triangle become the same shape once skewed at this size, and there
   are eighteen tiles on the IT page. */
/* Centred with left/right + text-align rather than a translate, unlike the
   header icon above - the hover lift below animates `transform`, and a
   transform carrying the centring too would be wiped out by it. The cube here
   is a single solid whose top face sits at (22,18) of a 44x50 viewBox drawn
   1:1, so the glyph's own line box lands it on that face without arithmetic.
   Change the font-size and this needs re-checking; the header's percentage
   anchoring does not. */
.module-grid .module-tile-icon > i {
  position: absolute;
  left: 0;
  right: 0;
  top: -1px;
  z-index: 2;
  text-align: center;
  font-size: 17px;
  line-height: 20px;
  color: var(--color-primary);
  filter: drop-shadow(0 3px 3px rgba(var(--color-primary-rgb), .30));
  transition: transform .22s ease;
}

.module-grid .module-tile:hover .module-tile-icon > i { transform: translateY(-3px); }

.module-grid .module-tile-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding-right: 14px; /* ที่ของดาว */
}

.module-grid .module-title {
  display: block;
  margin: 0;
  font-size: var(--font-size-md);
  font-weight: 600;
  line-height: 1.35;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.module-grid .module-desc {
  display: block;
  margin: 1px 0 0;
  font-size: var(--font-size-sm);
  line-height: 1.4;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Footer: the row count, or the old label when the registry declares none. */
.module-grid .module-foot {
  flex: none;
  align-self: flex-end;
  display: flex;
  align-items: center;
}

.module-grid .module-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  min-width: 0;
}

.module-grid .module-stat b {
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -.01em;
  color: var(--color-text-primary);
  font-variant-numeric: tabular-nums;
}

.module-grid .module-stat span {
  font-size: 11px;
  color: var(--color-text-muted);
}

/* Zero is a real answer, so it is shown - just quietly, so an empty register
   reads as empty rather than as a number that failed to load. */
.module-grid .module-stat.is-zero b { color: var(--color-text-muted); font-weight: 600; }

.module-grid .module-go { color: var(--color-primary); font-size: 12px; transition: transform .16s ease; }
.module-grid .module-tile:hover .module-go { transform: translateX(3px); }

/* การ์ดที่ข้อมูลดึงสดจาก TodaySoft (registry 'live_source' => 'todaysoft') - พื้นฟ้าอมเขียวอ่อน
   ไม่ใช่สีเหลือง เพราะไม่ใช่คำเตือน แค่บอกว่ามาจากระบบอื่น · เป็นค่าโปร่งแสงจึงใช้ได้ทั้งโหมดสว่างและมืด */
.module-grid .module-tile.is-live-source {
  background: linear-gradient(160deg, rgba(13, 202, 240, .16), rgba(13, 202, 240, .07) 70%), var(--color-bg-white);
  border-color: rgba(13, 202, 240, .38);
}
.module-grid .module-tile.is-live-source:hover,
.module-grid .module-tile.is-live-source:focus-visible { border-color: rgba(13, 202, 240, .75); }

/* Favourite star: secondary, out of the reading path, forward on hover. */
.module-grid .module-fav {
  position: absolute;
  top: 3px;
  right: 3px;
  border: 0;
  background: transparent;
  padding: 5px;
  line-height: 0;
  border-radius: var(--radius-full);
  color: var(--color-text-muted);
  opacity: .35;
  cursor: pointer;
  transition: opacity .16s ease, color .16s ease;
}

.module-grid .module-tile:hover .module-fav { opacity: .85; }
.module-grid .module-fav:hover { opacity: 1; color: var(--color-text-primary); }
.module-grid .module-fav.is-fav { opacity: 1; color: #f0a500; }
.module-grid .module-fav:focus-visible {
  opacity: 1;
  outline: 2px solid rgba(var(--color-primary-rgb), .55);
  outline-offset: 1px;
}

/* Empty state ------------------------------------------------------------- */
/* ── ไม่พบโมดูล ────────────────────────────────────────────────────────────
   สภาพว่างที่จางเกินไปอ่านเหมือน "หน้าเสีย" ไม่ใช่ "ค้นแล้วไม่เจอ" - ของเดิม
   เป็นไอคอนเทา 26px ที่ opacity .5 บนกล่องเส้นประ ซึ่งดูเหมือนรูปโหลดไม่ขึ้น
   สิ่งที่ต้องสื่อคือ: ระบบทำงานปกติ · คำค้นนี้ไม่มีผลลัพธ์ · แก้ได้ด้วยการพิมพ์ใหม่
   ───────────────────────────────────────────────────────────────────────── */
.module-empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 56px 24px 52px;
  border: 1px solid var(--color-border-light, var(--color-border));
  border-radius: var(--radius-lg);
  background: var(--color-bg-surface);
  text-align: center;
}

/* ไอคอนอยู่ในวงกลมพื้นอ่อน - ให้มันอ่านว่า "ภาพประกอบที่ตั้งใจวาง"
   ไม่ใช่ "ไอคอนที่โหลดไม่ขึ้น" ซึ่งเป็นสิ่งที่ไอคอนลอย ๆ จาง ๆ สื่อออกมา

   **`>` สำคัญ ห้ามตัดทิ้ง** - ในกล่องนี้มีไอคอนสองตัวคนละหน้าที่: ตัวใหญ่ที่เป็น
   ภาพประกอบ กับตัวเล็กที่อยู่ในปุ่ม เขียนเป็น `.module-empty i` เมื่อไร วงกลม
   68px จะไปครอบไอคอนในปุ่มด้วย แล้วปุ่มจะบวมทับข้อความ (เกิดจริงมาแล้ว) */
.module-empty > i {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  margin-bottom: 20px;
  border-radius: 50%;
  /* ไล่เฉดบาง ๆ ให้วงกลมมีมิติ แทนแผ่นสีเรียบที่ดูเหมือน placeholder */
  background:
    radial-gradient(circle at 50% 35%, var(--color-bg-surface), var(--color-bg-header) 70%);
  box-shadow: inset 0 0 0 1px var(--color-border-light, var(--color-border));
  font-size: 28px;
  color: var(--color-text-muted);
  opacity: 1;
}

.module-empty h6 {
  margin: 0;
  font-size: var(--font-size-lg);
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--color-text-primary);
}

/* กว้างจำกัดไว้ ~40 ตัวอักษร - บรรทัดคำอธิบายที่ยาวเต็มความกว้างจอ
   บังคับให้ตากวาดไกลเกินจำเป็นสำหรับข้อความสองบรรทัด */
.module-empty p {
  margin: 6px 0 0;
  max-width: 34ch;
  font-size: var(--font-size-md);
  line-height: 1.6;
  color: var(--color-text-muted);
}

/* คำที่ค้นไป - เน้นให้เห็นว่าระบบเข้าใจว่าเราพิมพ์อะไร คนที่พิมพ์ผิดหนึ่งตัว
   จะเห็นทันที แทนที่จะสงสัยว่าโมดูลหายไปไหน */
.module-empty-term {
  display: inline-block;
  max-width: 22ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  padding: 1px 8px;
  border-radius: var(--radius-sm);
  background: var(--color-bg-header);
  color: var(--color-text-primary);
  font-weight: 500;
}

/* ปุ่มเดียวในกล่องคือทางออกเดียว จึงให้มันดูกดได้จริง ไม่ใช่ปุ่มจาง ๆ
   ที่กลืนไปกับพื้น - แต่ยังเป็นโทนรอง เพราะการค้นใหม่ไม่ใช่การกระทำที่อันตราย */
.module-empty button {
  margin-top: 22px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 18px;
  border-radius: 999px;
}

/* ไอคอนในปุ่มต้องเป็นแค่ตัวอักษรตัวหนึ่ง - ล้างทุกอย่างที่วงกลมภาพประกอบตั้งไว้
   เผื่อวันหน้ามีคนเขียน `.module-empty i` ขึ้นมาอีก */
.module-empty button i {
  width: auto;
  height: auto;
  margin: 0;
  padding: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  font-size: var(--font-size-md);
  color: inherit;
}

.module-empty .btn-outline-secondary {
  border-color: var(--color-border-input, var(--color-border));
  color: var(--color-text-secondary);
  font-weight: 500;
}

.module-empty .btn-outline-secondary:hover {
  border-color: var(--color-primary);
  background: rgba(var(--color-primary-rgb), .06);
  color: var(--color-primary);
}

@media (max-width: 575.98px) {
  .module-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .module-head { gap: 10px; padding: 10px 12px; }
  .module-head-icon, .module-head-icon .iso-scene { width: 68px; height: 58px; }
  .module-head-tools { width: 100%; }
  .module-search, .module-search input { width: 100%; }
  .module-grid .module-tile { min-height: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .module-grid .module-tile,
  .module-grid .module-go,
  .module-grid .module-fav,
  .module-grid .module-tile-icon > i { transition: none; }
  .module-grid .module-tile:hover { transform: none; }
}

/* ── Grid cell decoration that carries information ────────────────────────
   The rule these follow: a glyph earns its width only when it DIFFERS between
   rows. An icon repeated identically down a column says nothing the header
   did not, and costs both space and scanning speed.
   ───────────────────────────────────────────────────────────────────────── */

/* The shape half of a status badge - the colour is the other half, and on its
   own it is unreadable to anyone who cannot separate red from green. Sized
   below the label so it reads as a mark, not as a second word. */
.badge .badge-mark {
  font-size: .85em;
  margin-right: 4px;
  vertical-align: baseline;
}

/* Status badges (the ones carrying a shape mark) are soft pills: tinted fill,
   dark ink, fully rounded. Count badges on filter chips have no mark and stay
   solid. Badges coloured from document_type_states arrive with an inline
   background and are left exactly as the table says. Colour still follows
   Utils_statusBadgeClass() - only how each class is painted changes. */
.badge:has(> .badge-mark):not([style*="background"]) {
  border-radius: 999px;
  font-weight: 600;
  padding: .3em .65em;
}
.badge:has(> .badge-mark):not([style*="background"]).bg-secondary { background-color: var(--pill-secondary-bg) !important; color: var(--pill-secondary-fg) !important; }
.badge:has(> .badge-mark):not([style*="background"]).bg-light     { background-color: var(--pill-secondary-bg) !important; color: var(--pill-secondary-fg) !important; }
.badge:has(> .badge-mark):not([style*="background"]).bg-warning   { background-color: var(--pill-warning-bg) !important;   color: var(--pill-warning-fg) !important; }
.badge:has(> .badge-mark):not([style*="background"]).bg-primary   { background-color: var(--pill-primary-bg) !important;   color: var(--pill-primary-fg) !important; }
.badge:has(> .badge-mark):not([style*="background"]).bg-success   { background-color: var(--pill-success-bg) !important;   color: var(--pill-success-fg) !important; }
.badge:has(> .badge-mark):not([style*="background"]).bg-danger    { background-color: var(--pill-danger-bg) !important;    color: var(--pill-danger-fg) !important; }
.badge:has(> .badge-mark):not([style*="background"]).bg-info      { background-color: var(--pill-info-bg) !important;      color: var(--pill-info-fg) !important; }

/* A person in a grid cell: face if there is one, coloured initials if not -
   and the second case is the common one (5 of 83 users have a photo). */
.grid-person {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  max-width: 100%;
}

.grid-person-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grid-avatar {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  background: var(--color-bg-surface);
  color: var(--color-text-muted);
  user-select: none;
}

.grid-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Same six tints workers.js already assigns on the card view, so the same
   person is the same colour in both places. Kept as their own class rather
   than reusing .worker-card-avatar: that one is 56px and card-specific. */
.grid-avatar.tint-1 { background: rgba(59, 130, 246, .14); color: #3b82f6; }
.grid-avatar.tint-2 { background: rgba(30, 126, 30, .14);  color: var(--color-status-active-fg); }
.grid-avatar.tint-3 { background: rgba(217, 119, 6, .16);  color: var(--color-warning-strong); }
.grid-avatar.tint-4 { background: rgba(124, 58, 237, .14); color: #7c3aed; }
.grid-avatar.tint-5 { background: rgba(14, 116, 144, .14); color: #0e7490; }
.grid-avatar.tint-6 { background: rgba(196, 43, 28, .12);  color: var(--color-status-inactive-fg); }

/* Dashboard widget headers - the small leading icon is decoration, not
   status; keep it quiet next to the title text. */
.widget-header h6 > i {
  color: var(--color-text-muted);
}

/* ปุ่มที่คนนี้ใช้ไม่ได้เพราะไม่มีสิทธิ์ (Wachi.Grid.permDenied / markPermButton) -
   จางลงแต่ยังอยู่ตรงนั้น คนจะได้รู้ว่ามีสิ่งนี้และต้องขอสิทธิ์อะไร (title บอกชื่อสิทธิ์)
   cursor: help คือสัญญาณว่ามีคำอธิบายให้ hover เหมือน .help-tip ด้านล่าง */
.wachi-perm-denied {
  opacity: .4;
  cursor: help;
}
.wachi-perm-denied:hover { opacity: .7; }

/* กริด/แผงที่เหลือ "อ่านอย่างเดียว" เพราะไม่มีสิทธิ์แก้ (Wachi.Grid.markReadOnly) -
   ห้ามลด opacity ทั้งก้อน ข้อมูลในนั้นยังต้องอ่านออกเต็มที่ ป้ายอยู่ที่ title */
.wachi-perm-readonly { cursor: help; }

/* "Where does this number come from" info icon (renderHelpTip()) -
   quiet next to its title/label, cursor signals a tooltip. */
.help-tip {
  color: var(--color-text-muted);
  opacity: .65;
  margin-left: .4rem;
  font-size: .78em;
  cursor: help;
}
.help-tip:hover { opacity: 1; }

/* The help texts are full sentences (Thai) - Bootstrap's default bubble
   (200px wide, .875rem text, tight padding) wraps them into a cramped
   sliver. Widen, left-align, and open up the type. Sizes are in px, not
   rem: the app pins html at 12px (tokens.css --font-size-base), which
   quietly shrinks Bootstrap's rem-based tooltip text to 10.5px. Thai
   stacks vowel/tone marks above and below the line, so it also needs the
   taller line-height to stay legible at these sizes. */
.help-tooltip {
  --bs-tooltip-max-width: 360px;
  --bs-tooltip-font-size: 13px;
  --bs-tooltip-padding-x: 12px;
  --bs-tooltip-padding-y: 9px;
  --bs-tooltip-border-radius: 6px;
  /* Amber bubble with near-black text in BOTH themes (~12:1 contrast) -
     reads like a sticky note against every surface, so the help texts
     don't need a per-theme variant here. theme-dark.css's generic dark
     .tooltip override excludes .help-tooltip for this reason. */
  --bs-tooltip-bg: #ffc107;
  --bs-tooltip-color: #111111;
  --bs-tooltip-opacity: 1;
}
.help-tooltip .tooltip-inner {
  text-align: left;
  line-height: 1.7;
}

/* ==========================================
   Widget loading skeleton - Wachi.Grid.setWidgetsLoading() toggles
   .is-loading on .widget-card while a dashboard refresh is in flight:
   the body's content hides and a shimmer block takes its place, so
   slow live queries (TodaySoft dashboards) read as "loading" instead
   of a blank page.
   ========================================== */
@keyframes wachi-shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
.widget-card.is-loading { position: relative; }
.widget-card.is-loading .widget-body { visibility: hidden; }
.widget-card.is-loading::after {
  content: '';
  position: absolute;
  left: var(--space-8);
  right: var(--space-8);
  top: 42px;
  bottom: var(--space-8);
  border-radius: var(--radius-md);
  background: linear-gradient(90deg,
    var(--color-bg-surface) 25%,
    var(--color-row-hover) 37%,
    var(--color-bg-surface) 63%);
  background-size: 400px 100%;
  animation: wachi-shimmer 1.2s linear infinite;
}

/* Stat-card delta badge (vs previous period of equal length) - rendered
   by Wachi.Grid.renderStatDelta(). good/bad follows the metric's own
   meaning (NG down = good, yield up = good), neutral metrics stay muted. */
.stat-delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: var(--space-4);
  font-size: var(--font-size-xs);
  font-weight: 600;
  vertical-align: middle;
}
.stat-delta.good { color: var(--color-status-active-fg); }
.stat-delta.bad  { color: var(--color-status-inactive-fg); }
.stat-delta.flat { color: var(--color-text-muted); }

/* ==========================================
   DataTables lot-detail child row - the expanded material trace used to
   render with the same visual weight as the parent rows (full grid
   borders, same background, no indent), so the eye could not tell where
   a lot ended and its detail began. Now it reads as an inset panel:
   tinted background, accent rail on the left, indented, and a quiet
   header. Density is unchanged - only weight and grouping.
   ========================================== */
table.dataTable tbody tr.dt-hasChild > td {
  background: var(--color-row-selected);
  font-weight: 600;
}
.lot-detail {
  background: var(--color-bg-surface);
  border-left: 3px solid var(--color-secondary);
  margin: 0 0 0 28px;
  padding: var(--space-5) var(--space-6);
}
.lot-detail table {
  margin-bottom: 0;
  background: transparent;
}
.lot-detail table > :not(caption) > * > * {
  background: transparent;
  border-bottom-color: var(--color-border-light);
  padding: var(--space-3) var(--space-5);
}
.lot-detail thead th {
  border-bottom: 1px solid var(--color-border) !important;
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
  white-space: nowrap;
}
.lot-detail tbody tr:last-child > td { border-bottom: 0; }
.lot-detail tfoot td {
  border-top: 1px solid var(--color-border);
  border-bottom: 0 !important;
}
/* Second table in the panel (per-PO claim summary on the NCR page) gets
   a divider so the two tables don't blur together. */
.lot-detail .lot-detail-section + .lot-detail-section {
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px dashed var(--color-border);
}
.lot-detail-title {
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
  margin-bottom: var(--space-3);
}

/* ==========================================
   AI Chatbot refresh (2026-08) - the page read as a 2010s form: a bare
   textarea + solid Send button, raw outline-button source toggle, and a
   vast empty canvas with nothing but a tiny italic system line. Now:
   a welcome state with clickable suggestion chips, a unified rounded
   composer with an icon-only send button, and pill source toggles that
   match the rest of the app.
   ========================================== */

/* -- Conversation column: cap the line length so long answers stay readable -- */
.chatbot-messages-inner {
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}
.chatbot-bubble { box-shadow: var(--elevation-1); }

/* -- Welcome / empty state -- */
.chatbot-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 100%;
  min-height: 240px;
  padding: var(--space-16) var(--space-8);
  gap: var(--space-5);
}
.chatbot-welcome-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary-bg, rgba(16, 42, 67, 0.08));
  color: var(--color-primary);
  font-size: 22px;
}
.chatbot-welcome-title { font-size: var(--font-size-title); font-weight: 600; color: var(--color-text-primary); }
.chatbot-welcome-subtitle { font-size: var(--font-size-md); color: var(--color-text-muted); max-width: 520px; }
.chatbot-suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-5);
  margin-top: var(--space-5);
  max-width: 720px;
}
.chatbot-suggestion {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-10);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg-white);
  color: var(--color-text-secondary);
  font-size: var(--font-size-md);
  cursor: pointer;
  transition: var(--transition-ui);
}
.chatbot-suggestion i { color: var(--color-text-muted); }
.chatbot-suggestion:hover {
  border-color: var(--color-primary);
  color: var(--color-text-primary);
  box-shadow: var(--elevation-1);
  transform: translateY(-1px);
}
.chatbot-suggestion:hover i { color: var(--color-primary); }

/* -- Composer: one rounded field holding the textarea + circular send -- */
.chatbot-composer {
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  padding-bottom: var(--space-8);
}
.chatbot-composer-box {
  display: flex;
  align-items: flex-end;
  gap: var(--space-5);
  padding: var(--space-5) var(--space-5) var(--space-5) var(--space-10);
  border: 1px solid var(--color-border-input);
  border-radius: 22px;
  background: var(--color-bg-white);
  box-shadow: var(--elevation-1);
  transition: var(--transition-ui);
}
.chatbot-composer-box:focus-within {
  border-color: var(--color-primary);
  box-shadow: var(--elevation-2);
}
.chatbot-composer-box textarea.form-control {
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: var(--space-4) 0;
  resize: none;
  max-height: 140px;
}
.chatbot-composer-box textarea.form-control:focus { box-shadow: none; }
.chatbot-send-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary);
  color: var(--color-on-accent);
  transition: var(--transition-ui);
}
.chatbot-send-btn:hover:not(:disabled) { background: var(--color-primary-hover); }
.chatbot-send-btn:disabled { opacity: .45; }
.chatbot-composer-hint {
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  margin-top: var(--space-4);
}

/* -- Source toggle as segmented pills (matches .range-btn / .metric-btn) -- */
.btn-group:has(> .chatbot-source-btn) {
  background: var(--color-bg-header);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}
.btn-group > .chatbot-source-btn {
  border: 0 !important;
  border-radius: 999px !important;
  background: transparent;
  color: var(--color-text-light);
  transition: var(--transition-ui);
}
.btn-group > .chatbot-source-btn:hover:not(.active) {
  background: var(--color-row-hover);
  color: var(--color-text-primary);
}
.btn-group > .chatbot-source-btn.active {
  background: var(--color-primary);
  color: var(--color-on-accent);
  box-shadow: var(--elevation-1);
}

/* -- Quick-chats panel: quiet the jstree file-explorer look -- */
.chatbot-quick-tree .jstree-wholerow-hovered {
  background: var(--color-row-hover);
  border-radius: var(--radius-sm);
}
.chatbot-quick-tree .jstree-wholerow-clicked {
  background: var(--color-row-selected);
  border-radius: var(--radius-sm);
}
.chatbot-quick-tree .jstree-anchor { color: var(--color-text-secondary); }
.chatbot-quick-tree .jstree-anchor:hover { color: var(--color-text-primary); }

/* ==========================================
   Asset cards (card view on ?route=assets) - the old card stacked four
   colored badges over two rows, printed a field label for every value,
   rendered em-dash rows for empty fields (most cards carried two dead
   rows plus a "no description" filler line), and hardcoded a light
   #f8f9fa image well that glared white in dark mode. This version keeps
   every piece of information but spends the space on data instead of
   chrome, so a card is ~30% shorter.
   ========================================== */
.asset-card {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: var(--transition-ui);
}
.asset-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--elevation-2);
  transform: translateY(-2px);
}

/* -- Media well: theme-aware (was hardcoded #f8f9fa = white box in dark mode) -- */
.asset-card-media {
  position: relative;
  height: 130px;
  background: var(--color-bg-header);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.asset-card-media img { width: 100%; height: 100%; object-fit: cover; }

/* Photo count sits ON the image as a quiet glass chip instead of
   competing with the status badges down in the body. */
.asset-card-photos {
  position: absolute;
  top: var(--space-4);
  left: var(--space-4);
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px var(--space-5);
  border-radius: 999px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: var(--font-size-xs);
  line-height: 1.6;
}

/* Actions reveal on hover over the media area - no permanent button row
   with text labels at the bottom of every card. */
.asset-card-actions {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  display: flex;
  gap: var(--space-3);
  opacity: 0;
  transform: translateY(-4px);
  transition: var(--transition-ui);
}
.asset-card:hover .asset-card-actions,
.asset-card:focus-within .asset-card-actions { opacity: 1; transform: translateY(0); }
.asset-card-action {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  transition: var(--transition-ui);
}
.asset-card-action:hover { background: var(--color-primary); color: var(--color-on-accent); }

.asset-card-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-8) var(--space-8);
  flex: 1 1 auto;
  min-width: 0;
}
.asset-card-code {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: .2px;
}
.asset-card-name {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--color-text-primary);
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.asset-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-3);
}
.asset-card-badges .badge { font-weight: 600; }

/* Facts: icon + value, no repeated field-name column. Rows with no
   value are simply not rendered (see assets.js). */
.asset-card-facts {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px solid var(--color-border-light);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}
.asset-card-fact {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  min-width: 0;
}
.asset-card-fact > i {
  flex-shrink: 0;
  width: 12px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--icon-size-sm);
}
.asset-card-fact > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================
   Worker cards (card view on ?route=workers) - a people directory card.
   Portrait-first: the photo is the anchor a human scans for, so it sits
   large and centered at the top with the identity beneath it, and the
   record's facts follow in a quiet block. Only ~7% of workers have a
   photo on file, so the initial fallback is styled to look deliberate
   (deterministic tint per person) rather than like a missing image.
   ========================================== */
.worker-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  padding: var(--space-10) var(--space-8) var(--space-8);
  background: var(--card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  text-align: center;
  transition: var(--transition-ui);
}
.worker-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--elevation-2);
  transform: translateY(-2px);
}

.worker-card-avatar {
  flex-shrink: 0;
  width: 92px;
  height: 92px;
  margin-bottom: var(--space-6);
  border-radius: var(--radius-full);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-header);
  color: var(--color-primary);
  font-size: 34px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
  box-shadow: 0 0 0 3px var(--card-bg), 0 0 0 4px var(--color-border);
  transition: var(--transition-ui);
}
.worker-card:hover .worker-card-avatar {
  box-shadow: 0 0 0 3px var(--card-bg), 0 0 0 4px var(--color-primary);
}
.worker-card-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Deterministic tint per person (assigned in workers.js from a hash of
   the name) so a screen full of initials reads as a directory rather
   than as one repeated placeholder. */
.worker-card-avatar.tint-1 { background: rgba(59, 130, 246, .14); color: #3b82f6; }
.worker-card-avatar.tint-2 { background: rgba(30, 126, 30, .14);  color: var(--color-status-active-fg); }
.worker-card-avatar.tint-3 { background: rgba(217, 119, 6, .16);  color: var(--color-warning-strong); }
.worker-card-avatar.tint-4 { background: rgba(124, 58, 237, .14); color: #7c3aed; }
.worker-card-avatar.tint-5 { background: rgba(14, 116, 144, .14); color: #0e7490; }
.worker-card-avatar.tint-6 { background: rgba(196, 43, 28, .12);  color: var(--color-status-inactive-fg); }

.worker-card-main { width: 100%; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.worker-card-name {
  width: 100%;
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--color-text-primary);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.worker-card-role {
  width: 100%;
  font-size: var(--font-size-md);
  color: var(--color-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.worker-card-code { font-size: var(--font-size-xs); color: var(--color-text-muted); }
.worker-card-badges { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-3); margin-top: var(--space-4); }
.worker-card-badges .badge { font-weight: 600; }

.worker-card-facts {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--color-border-light);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  text-align: left;
}
.worker-card-fact { display: flex; align-items: center; gap: var(--space-5); min-width: 0; }
.worker-card-fact > i {
  flex-shrink: 0;
  width: 12px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--icon-size-sm);
}
.worker-card-fact > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Edit action appears on hover, like the asset cards */
.worker-card-action {
  position: absolute;
  top: var(--space-5);
  right: var(--space-5);
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-header);
  color: var(--color-text-muted);
  font-size: 12px;
  opacity: 0;
  transition: var(--transition-ui);
}
.worker-card:hover .worker-card-action,
.worker-card:focus-within .worker-card-action { opacity: 1; }
.worker-card-action:hover { background: var(--color-primary); color: var(--color-on-accent); }

/* --------------------------------------------------------------------------
   GRID AVATAR

   รูปพนักงานในตาราง - ตัวเล็กพอที่แถวยังสูงเท่าเดิม (28px ในแถวสูง 34px)
   คนที่ไม่มีรูปได้วงกลมตัวอักษรแรกแทน ไม่ใช่ช่องว่าง เพราะคอลัมน์ที่ว่างเป็น
   ส่วนใหญ่จะดูเหมือนตารางเสีย - ตอนนี้มีรูปแค่ 18 คนจาก 244 คน
   -------------------------------------------------------------------------- */
.grid-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  object-fit: cover;
  vertical-align: middle;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-header);
  color: var(--color-primary);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
}

/* ============================================================
   DAY LANES - แถบงานรายวัน แยกตามคน (Wachi.Charts.renderDayLanes)
   ------------------------------------------------------------
   วาดเองด้วย CSS ไม่ผ่าน ApexCharts เพราะสองอย่างที่มุมมองนี้ต้องมี แต่
   rangeBar ทำไม่ได้: รูปคนบนหัวแถว (ป้ายแกน y รับได้แต่ข้อความ) และแท่ง
   หลายอันที่ทับซ้อนกันในแถวเดียวโดยเห็นทั้งคู่ ซึ่งคือทั้งหมดของคำถาม
   "คนนี้ช่วงบ่ายทำสองอย่างพร้อมกันหรือเปล่า"
   ตำแหน่งแท่งเป็น % ของช่วงเวลาทำงาน คำนวณจากฝั่ง JS
   ============================================================ */
.day-lanes { display: flex; flex-direction: column; font-size: 11px; }

.day-lanes-head { display: flex; align-items: flex-end; border-bottom: 1px solid var(--color-border); }
.day-lanes-head .day-lane-person { border-bottom: 0; }

.day-lanes-hours { position: relative; flex: 1; height: 22px; }
.day-lanes-hour {
  position: absolute; top: 0; bottom: 0;
  border-left: 1px solid var(--color-border-light);
  padding-left: 3px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.day-lane { display: flex; align-items: stretch; border-bottom: 1px solid var(--color-border-light); }
.day-lane:last-child { border-bottom: 0; }

/* หัวแถว: กว้างคงที่ เพื่อให้เส้นชั่วโมงของทุกแถวตรงกันพอดี */
.day-lane-person {
  flex: none; width: 150px;
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px 6px 0;
  border-right: 1px solid var(--color-border);
  overflow: hidden;
}
.day-lane-person .grid-avatar { width: 26px; height: 26px; font-size: 10px; }
.day-lane-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.day-lane-count { color: var(--color-text-muted); font-weight: 400; }

.day-lane-track { position: relative; flex: 1; min-height: 38px; padding: 4px 0; }

/* เส้นแบ่งชั่วโมงจาง ๆ ให้กะเวลาได้โดยไม่ต้องลากสายตาขึ้นไปที่หัวตาราง */
.day-lane-grid { position: absolute; inset: 0; pointer-events: none; }
.day-lane-grid span { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--color-border-light); }

.day-lane-bar {
  position: absolute; height: 20px;
  border-radius: 4px;
  color: #fff;
  padding: 0 6px;
  display: flex; align-items: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
}
.day-lane-bar:hover { filter: brightness(1.08); }

/* งานที่ไม่ได้ระบุเวลา = ทั้งวัน วาดเป็นลายทางเพื่อไม่ให้อ่านผิดว่าจับเวลาไว้จริง */
.day-lane-bar.is-all-day {
  background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.22) 0 6px, transparent 6px 12px);
  opacity: .85;
}

/* เส้นเวลาปัจจุบัน - ตอบว่า "ตอนนี้" อยู่ตรงไหนของวันโดยไม่ต้องดูนาฬิกา */
.day-lanes-now { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--color-status-inactive-fg, #c42b1c); z-index: 2; }
.day-lanes-now::after {
  content: ''; position: absolute; top: -3px; left: -3px;
  width: 8px; height: 8px; border-radius: var(--radius-full);
  background: var(--color-status-inactive-fg, #c42b1c);
}

.day-lanes-empty { padding: 28px 8px; text-align: center; color: var(--color-text-muted); }

/* =============================================================================
   Kanban board — กระดานลากย้ายขั้นของดีล (leads_board)
   ใช้ token ล้วน จึงไม่ต้องมี override ใน theme-dark.css
   ============================================================================= */

.kanban-board {
  display: flex;
  gap: var(--space-10);
  align-items: flex-start;
  overflow-x: auto;
  overflow-y: hidden;
  padding: var(--space-10);
  flex: 1 1 auto;
  min-height: 0;
}

.kanban-col {
  flex: 0 0 288px;
  display: flex;
  flex-direction: column;
  max-height: 100%;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.kanban-col-head {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-6) var(--space-8);
  border-bottom: 1px solid var(--color-border);
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
}
.kanban-col-head .kanban-col-count {
  margin-left: auto;
  font-weight: 400;
  color: var(--color-text-muted);
}
/* ยอดรวมของคอลัมน์อยู่ใต้ชื่อขั้น - กระดานที่บอกแค่จำนวนใบตอบไม่ได้ว่า
   ขั้นไหนถือเงินไว้เท่าไร ซึ่งเป็นคำถามที่คนเปิดกระดานมาถามจริง */
.kanban-col-total {
  padding: var(--space-4) var(--space-8) var(--space-6);
  font-size: 11px;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border-light);
}

.kanban-col-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  min-height: 80px;
}

/* คอลัมน์ที่การ์ดกำลังลอยอยู่เหนือ - ต้องเห็นชัดว่าปล่อยแล้วจะลงตรงไหน */
.kanban-col.is-drop-target { border-color: var(--color-primary); }
.kanban-col.is-drop-target .kanban-col-body {
  background: rgba(var(--color-primary-rgb), .06);
  outline: 2px dashed rgba(var(--color-primary-rgb), .45);
  outline-offset: -4px;
  border-radius: var(--radius-sm);
}

.kanban-card {
  position: relative;
  background: var(--color-bg-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-6) var(--space-8) var(--space-6) var(--space-10);
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
  cursor: grab;
  transition: border-color .12s ease, box-shadow .12s ease, transform .12s ease;
  /* ไม่ให้เบราว์เซอร์ scroll ตอนลากบนจอสัมผัส - ตัวลากใช้ pointer event
     ซึ่งทำงานทั้งเมาส์และนิ้ว ต่างจาก HTML5 drag ที่ไม่รองรับสัมผัส */
  touch-action: none;
  user-select: none;
}
.kanban-card:hover {
  border-color: var(--color-border-medium);
  box-shadow: 0 2px 6px rgba(0,0,0,.10);
  transform: translateY(-1px);
}
.kanban-card:active { cursor: grabbing; }

/* ที่ว่างที่การ์ดจากมา - กันไม่ให้คอลัมน์กระโดดตอนยกการ์ดขึ้น */
.kanban-card.is-ghost { opacity: .35; }

/* การ์ดที่กำลังลอยตามเคอร์เซอร์ */
.kanban-card.is-dragging {
  position: fixed;
  z-index: 1080;
  pointer-events: none;
  box-shadow: 0 8px 20px rgba(0,0,0,.22);
  cursor: grabbing;
}

/* แถบสีขั้นด้านซ้ายของการ์ด - ตอนลากขึ้นมาลอยอยู่กลางจอ การ์ดจะหลุดจากคอลัมน์
   ของมัน สีนี้คือสิ่งเดียวที่ยังบอกว่ามันมาจากขั้นไหน */
.kanban-card::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--stage-color, var(--color-border-medium));
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.kanban-card-top {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  margin-bottom: var(--space-3);
}
/* เลขที่เอกสารเป็นตัวเลขที่คนอ่านทีละหลัก - ตัวพิมพ์ความกว้างเท่ากันอ่านง่ายกว่า */
.kanban-card-no {
  font-family: var(--font-mono, ui-monospace, 'Cascadia Mono', Consolas, monospace);
  font-size: 10px;
  letter-spacing: .2px;
  color: var(--color-text-muted);
}
/* ปุ่มเปิดรายละเอียดเป็นลิงก์จริง เปิดแท็บใหม่ได้ - โผล่ตอนชี้ที่การ์ด เพราะทั้งใบ
   คลิกเปิดได้อยู่แล้ว ปุ่มนี้มีไว้บอกว่าคลิกได้ ไม่ใช่ทางเดียวที่จะเข้า */
.kanban-card-open {
  margin-left: auto;
  color: var(--color-text-muted);
  font-size: 11px;
  opacity: 0;
  transition: opacity .12s ease;
}
.kanban-card:hover .kanban-card-open,
.kanban-card-open:focus-visible { opacity: 1; }
.kanban-card-open:hover { color: var(--color-primary); }

.kanban-card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: var(--space-3);
  overflow-wrap: anywhere;
}
.kanban-card-party { font-size: 11px; color: var(--color-text-light); margin-bottom: var(--space-5); }

/* โอกาสปิดมาจากทะเบียนขั้น - แถบยาวตามเปอร์เซ็นต์ ทาสีของขั้นนั้น กวาดตาทีเดียว
   ก็เทียบข้ามการ์ดได้ ต่างจากตัวเลขเปล่าที่ต้องอ่านทีละใบ */
.kanban-card-chance { margin-bottom: var(--space-5); }
.kanban-chance-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}
.kanban-chance-pct { font-weight: 600; color: var(--color-text-secondary); }
.kanban-chance-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--color-bg-subtle, rgba(0,0,0,.07));
  overflow: hidden;
}
.kanban-chance-bar > span { display: block; height: 100%; border-radius: 2px; }

/* ดีลที่จบแล้วบอกเหตุผลแทนโอกาส */
.kanban-card-reason {
  font-size: 10px;
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
  overflow-wrap: anywhere;
}

.kanban-card-foot {
  display: flex;
  align-items: center;
  gap: var(--space-5);
}
.kanban-card-value { font-weight: 600; font-size: 12px; color: var(--color-text-secondary); }

/* รูปเซลล์ - คนที่ยังไม่มีรูปได้อักษรย่อ ไม่ใช่ช่องว่างที่ทำให้การ์ดเรียงไม่ตรงกัน */
.kanban-avatar {
  margin-left: auto;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--color-text-white, #fff);
  border: 1px solid var(--color-bg-white);
  box-shadow: 0 0 0 1px var(--color-border-light);
}
.kanban-avatar.is-empty {
  background: var(--color-bg-subtle, #e9ecef);
  color: var(--color-text-muted);
}

.kanban-card-meta {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  flex-wrap: wrap;
  font-size: 10px;
  color: var(--color-text-muted);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border-light);
}
/* วันติดตามที่เลยมาแล้ว - จุดที่ดีลตายจริง ไม่ใช่ตอนลูกค้าปฏิเสธ */
.kanban-card-due.is-overdue { color: var(--color-status-inactive-fg, #c42b1c); font-weight: 600; }

.kanban-col-empty {
  padding: var(--space-16) var(--space-8);
  text-align: center;
  font-size: 11px;
  color: var(--color-text-muted);
}

/* ขั้นที่จบแล้วเป็นคอลัมน์เต็มเหมือนขั้นอื่น แต่ต้องอ่านออกทันทีว่าไม่ใช่งานที่ยัง
   วิ่งอยู่ - เว้นช่องกับเส้นประคั่นไว้ ไม่ใช่ให้ปนไปกับไปป์ไลน์เฉย ๆ
   ปล่อยการ์ดลงคอลัมน์พวกนี้เปิดฟอร์มปิดดีล ไม่ได้ย้ายขั้นเงียบ ๆ */
.kanban-col-closed {
  margin-left: var(--space-10);
  border-style: dashed;
  background: var(--color-bg-subtle, var(--color-bg-surface));
}
.kanban-col-closed + .kanban-col-closed { margin-left: 0; }
.kanban-col-closed .kanban-col-body { opacity: .85; }

/* บอกว่าที่วาดไม่ครบ - ดีลที่เสียไปมีหลักพัน กระดานวาดแค่ล่าสุด · ไม่บอกตรงนี้
   คนจะนับการ์ดแล้วเชื่อว่านั่นคือทั้งหมด */
.kanban-col-more {
  padding: var(--space-4) var(--space-8) var(--space-6);
  font-size: 11px;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border-light);
}
.kanban-col-more:empty { display: none; }

.kanban-col-closed.is-drop-target { border-style: solid; }
.kanban-col-closed.closer-won.is-drop-target {
  border-color: var(--color-status-active-fg, #107c10);
}
.kanban-col-closed.closer-won.is-drop-target .kanban-col-body {
  background: rgba(16, 124, 16, .08);
  outline-color: rgba(16, 124, 16, .45);
}
.kanban-col-closed.closer-lost.is-drop-target {
  border-color: var(--color-status-inactive-fg, #c42b1c);
}
.kanban-col-closed.closer-lost.is-drop-target .kanban-col-body {
  background: rgba(196, 43, 28, .08);
  outline-color: rgba(196, 43, 28, .45);
}
