/* =====================================================================
   YourHR — Component Library (app.css)
   Premium Modern SaaS UI built on theme.css tokens, layered over Bootstrap 5.
   Back-compatible: all legacy class names (.stat-card,.badge-soft,.state,…) kept.
   ===================================================================== */

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-base);
  line-height: var(--lh);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: .1px;
}
a { text-decoration: none; color: var(--brand-text); }
a:hover { color: var(--brand-600); }
[data-theme="dark"] a:hover { color: #a5b4fc; }
/* btn-link ใช้สีลิงก์ตามธีม (กัน fallback Bootstrap #0d6efd ที่ contrast ต่ำบนการ์ดมืด — a11y WCAG AA) */
.btn-link { color: var(--brand-text); }
.btn-link:hover, .btn-link:focus { color: var(--brand-600); }
[data-theme="dark"] .btn-link:hover, [data-theme="dark"] .btn-link:focus { color: #a5b4fc; }
hr { border-color: var(--border); opacity: 1; }
::selection { background: var(--brand-soft-2); }
/* F-12: solid outline is the load-bearing focus indicator (survives overflow:hidden ancestors,
   honored by Windows High Contrast); box-shadow ring reinforces it. Theme-aware via tokens. */
:focus-visible { outline: 2px solid var(--ring-outline); outline-offset: 2px; box-shadow: var(--ring); border-radius: var(--r-xs); }
small { font-size: .8em; }

/* premium scrollbars (tokenized for dark-mode via --scroll-thumb) */
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 99px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: #aab4c6; background-clip: padding-box; }

/* ---------- Auth (F-14: 2-pane card — hero + form, softened backdrop) ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg,#eef2ff 0%,#e0e7ff 60%,#c7d2fe 100%);
  padding: 1.5rem; position: relative; overflow: hidden;
}
.auth-wrap::before, .auth-wrap::after {
  content: ""; position: absolute; border-radius: 50%; filter: blur(60px); opacity: .18;
}
.auth-wrap::before { width: 300px; height: 300px; background: #a5b4fc; top: -120px; right: -80px; }
.auth-wrap::after { width: 260px; height: 260px; background: #6366f1; bottom: -140px; left: -90px; }
.auth-card {
  width: 100%; max-width: 880px; background: var(--surface); position: relative; z-index: 1;
  border-radius: var(--r-xl); box-shadow: var(--sh-lg); padding: 0; overflow: hidden;
  border: 1px solid rgba(255,255,255,.5);
  display: grid; grid-template-columns: 1fr 1fr;
}
.auth-hero {
  background: var(--brand-grad); color: #fff;
  padding: 2.75rem 2.4rem; display: flex; flex-direction: column; justify-content: center; gap: .85rem;
}
.auth-hero .auth-logo { color: #fff; }
.auth-hero .auth-logo small { color: rgba(255,255,255,.85); }
.auth-hero h2 { font-size: 1.3rem; font-weight: var(--fw-bold); margin: .25rem 0 0; }
.auth-hero p { margin: 0; color: rgba(255,255,255,.85); font-size: .9rem; line-height: 1.6; }
.auth-hero ul { list-style: none; padding: 0; margin: .5rem 0 0; display: flex; flex-direction: column; gap: .55rem; }
.auth-hero li { display: flex; align-items: center; gap: .6rem; font-size: .875rem; color: rgba(255,255,255,.92); }
.auth-hero li i { font-size: 1.05rem; }
.auth-form { padding: 2.5rem 2.25rem; }
.auth-logo { font-weight: var(--fw-black); font-size: 1.7rem; color: var(--brand); letter-spacing: -.5px; }
.auth-logo small { color: var(--text); }
.demo-login-btn { font-size: .82rem; }

/* Platform (control-plane) login — ธีมศูนย์ควบคุมส่วนกลาง สีเข้มพรีเมียม แยกจาก tenant */
.platform-card { max-width: 920px; }
.auth-hero.platform-hero {
  background: radial-gradient(120% 120% at 0% 0%, #1e293b 0%, #0f172a 55%, #020617 100%);
  position: relative; overflow: hidden;
}
.auth-hero.platform-hero::after {
  content: ""; position: absolute; width: 340px; height: 340px; border-radius: 50%;
  background: radial-gradient(circle, rgba(99,102,241,.45), transparent 70%); top: -120px; right: -110px; filter: blur(8px);
}
.auth-hero.platform-hero > * { position: relative; z-index: 1; }
.platform-badge {
  display: inline-flex; align-items: center; gap: .4rem; align-self: flex-start;
  background: rgba(99,102,241,.18); color: #c7d2fe; border: 1px solid rgba(129,140,248,.4);
  padding: .25rem .7rem; border-radius: 999px; font-size: .72rem; font-weight: var(--fw-bold);
  text-transform: uppercase; letter-spacing: .08em;
}
.platform-badge i { font-size: .7rem; }
.platform-hero h2 { color: #fff; }
.platform-hero p { color: rgba(226,232,240,.82); }
.platform-hero li { color: rgba(226,232,240,.95); }
.platform-hero li i { color: #818cf8; }
.platform-hero-foot {
  margin-top: 1.1rem; padding-top: 1rem; border-top: 1px solid rgba(148,163,184,.22);
  font-size: .8rem; color: rgba(148,163,184,.9); display: flex; align-items: center; gap: .45rem;
}
.platform-btn { background: #0f172a; border-color: #0f172a; }
.platform-btn:hover, .platform-btn:focus { background: #1e293b; border-color: #1e293b; }
/* form-pane logo บน platform = โทนเข้ม (ไม่ใช่ brand น้ำเงิน) ให้เข้าธีม */
.platform-card .auth-form .auth-logo { color: #0f172a; }
.platform-card .auth-form .auth-logo span { color: var(--brand); }

@media (max-width: 767.98px) {
  .auth-card { grid-template-columns: 1fr; max-width: 430px; }
  .auth-hero { display: none; }
  .auth-form { padding: 2.25rem 1.75rem; }
}

/* ---------- Auth — dark theme (auth-dark) ----------
   Logged-out pages (login/forgot/invite/gps/platform login) had a hard-coded light
   backdrop + glass edges + language pill, so a visitor who picked dark mode still got a
   blinding light screen. Re-tint the auth-only surfaces to dark tokens; the form pane,
   inputs, alerts and buttons already ride Bootstrap/global dark vars from theme.css.
   The .auth-hero (brand gradient) and .platform-hero (deep navy) stay dark in both modes
   by design, so they need no override. */
[data-theme="dark"] .auth-wrap {
  background: linear-gradient(160deg,#0b1120 0%,#111c30 60%,#1b2742 100%);
}
[data-theme="dark"] .auth-wrap::before { background: #4338ca; opacity: .22; }
[data-theme="dark"] .auth-wrap::after  { background: #6366f1; opacity: .20; }
[data-theme="dark"] .auth-card {
  border-color: var(--border);
  box-shadow: var(--sh-lg);
}
/* mobile logo wordmark uses Bootstrap .text-dark on the "HR" span — invisible on a dark
   surface; in dark the auth surface is light-on-dark, so force it readable. */
[data-theme="dark"] .auth-form .auth-logo .text-dark { color: var(--text) !important; }
/* platform form-pane logo is hard-set to #0f172a (near-black) for the light card — flip it
   to the light foreground token so it reads on the dark surface. */
[data-theme="dark"] .platform-card .auth-form .auth-logo { color: var(--text); }
/* language pill: swap the frosted-white chip + slate text for dark-surface equivalents. */
[data-theme="dark"] .auth-lang {
  background: rgba(18,28,48,.78); border-color: var(--border);
}
[data-theme="dark"] .auth-lang > .bi-translate { color: var(--muted); }
[data-theme="dark"] .auth-lang-opt { color: var(--text-2); }
[data-theme="dark"] .auth-lang-opt:hover { background: rgba(255,255,255,.08); color: var(--text); }
[data-theme="dark"] .auth-lang-opt.active { background: var(--brand-600); color: #fff; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--side-w); color: var(--side-text);
  position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column;
  z-index: var(--z-side); transition: transform var(--t) var(--ease); overflow: hidden;
  /* background/border/box-shadow driven by Block C (light default + dark) below */
}
/* 3-zone sidebar: brand (pinned top) · nav (scrollable middle) · footer (pinned bottom, always visible) */
.sidebar .side-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: .5rem; }
.sidebar .side-scroll { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent; }
.sidebar .side-scroll::-webkit-scrollbar { width: 8px; }
.sidebar .side-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,.16); border-radius: 99px; background-clip: padding-box; border: 2px solid transparent; }
.sidebar .brand {
  flex: 0 0 auto;
  padding: 1.15rem 1.35rem .9rem; font-weight: var(--fw-black); font-size: 1.25rem;
  letter-spacing: -.3px; display: flex; align-items: center; gap: .55rem;
  /* color + background handled by Block C (light default + dark) below */
}
.sidebar .brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .brand-mark {
  width: 34px; height: 34px; border-radius: 10px; background: var(--brand-grad); display: grid; place-items: center;
  color: #fff; font-size: 1.05rem; box-shadow: 0 4px 12px var(--brand-shadow); flex: 0 0 auto; overflow: hidden;
}
/* white-label: โลโก้จริงแทนไอคอน (พื้นขาวเล็กน้อยให้โลโก้สีอ่านออกบน sidebar เข้ม) */
.sidebar .brand-mark.has-img { background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.sidebar .brand-mark img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.sidebar .nav-section {
  padding: .9rem 1.35rem .3rem; font-size: .66rem; text-transform: uppercase; letter-spacing: .1em;
  color: var(--side-section); font-weight: var(--fw-bold);
}
/* F-02: collapsible accordion group headers (button) + collapse container */
.sidebar .nav-group-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  width: 100%; background: transparent; border: 0; cursor: pointer; font-family: inherit;
  text-align: left;
}
.sidebar .nav-group-toggle:hover { color: var(--side-text); }
.sidebar .nav-group-toggle:hover .nav-group-chevron { color: var(--side-text); }
/* F-12: light focus ring on the deep-navy sidebar (brand-400 ≈ 6:1 on navy).
   Inset (outline-offset:-2px) so the ring is NOT clipped by the .nav-group overflow:hidden on edge items. */
.sidebar .nav-group-toggle:focus-visible, .sidebar a.nav-item:focus-visible { outline: 2px solid var(--brand-400); outline-offset: -2px; box-shadow: none; border-radius: var(--r-xs); }
.sidebar .nav-group-chevron { font-size: .7rem; color: var(--side-section); transition: transform var(--t-fast) var(--ease); }
.sidebar .nav-group-toggle[aria-expanded="false"] .nav-group-chevron { transform: rotate(-90deg); }
/* collapse via grid 0fr↔1fr — animates to the group's NATURAL height, never clips regardless of item count */
.sidebar .nav-group { display: grid; grid-template-rows: 1fr; transition: grid-template-rows var(--t) var(--ease); }
.sidebar .nav-group:not(.open) { grid-template-rows: 0fr; }
.sidebar .nav-group-inner { overflow: hidden; min-height: 0; }
@media (prefers-reduced-motion: reduce) {
  .sidebar .nav-group { transition: none; }
  .sidebar .nav-group-chevron { transition: none; }
}
.sidebar a.nav-item {
  display: flex; align-items: center; gap: .75rem; margin: .07rem .6rem; padding: .56rem .75rem;
  color: var(--side-text); font-size: .885rem; border-radius: var(--r-sm); font-weight: var(--fw-medium);
  position: relative; transition: background var(--t-fast), color var(--t-fast);
}
.sidebar a.nav-item i { width: 20px; text-align: center; font-size: 1.08rem; color: var(--side-muted); transition: color var(--t-fast); }
.sidebar a.nav-item span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar a.nav-item:hover { background: var(--side-hover); color: #fff; }
.sidebar a.nav-item:hover i { color: var(--side-text); }
.sidebar a.nav-item.active { background: var(--side-active-bg); color: var(--side-active-tx); font-weight: var(--fw-bold); }
.sidebar a.nav-item.active i { color: var(--brand-400); }
.sidebar a.nav-item.active::before {
  content: ""; position: absolute; left: -.6rem; top: 12%; bottom: 12%; width: 4px;
  background: var(--brand-400); border-radius: 0 4px 4px 0; box-shadow: 0 0 8px 0 var(--brand-400);
}
.sidebar .side-foot { flex: 0 0 auto; padding: .5rem .6rem; border-top: 1px solid rgba(255,255,255,.07); background: var(--side-bg-2); }
/* R-04: language selector ใน sidebar (ย้ายมาจาก top bar) */
.sidebar .side-lang { display: flex; align-items: center; gap: .3rem; padding: .25rem .6rem .45rem; color: var(--side-muted); font-size: .78rem; }
.sidebar .side-lang > i { font-size: .9rem; margin-right: .15rem; }
.sidebar .side-lang-btn { padding: .12rem .55rem; border-radius: var(--r-xs); color: var(--side-text); font-weight: var(--fw-bold); font-size: .74rem; text-decoration: none; transition: background var(--t-fast), color var(--t-fast); min-height: 28px; display: inline-flex; align-items: center; }
.sidebar .side-lang-btn:hover { background: var(--side-hover); color: #fff; }
.sidebar .side-lang-btn.active { background: var(--brand); color: #fff; }
/* Language switcher (ย้ายมาจาก topbar) — segmented control ใน sidebar foot */
.sidebar .side-lang { display: flex; align-items: center; gap: .35rem; padding: .25rem .35rem .5rem; }
.sidebar .side-lang > .bi-translate { color: rgba(255,255,255,.55); font-size: .9rem; }
.sidebar .side-lang-opt { flex: 1; text-align: center; padding: .28rem .3rem; border-radius: 7px; font-size: .82rem;
  color: rgba(255,255,255,.65); text-decoration: none; border: 1px solid transparent; transition: background .15s, color .15s; }
.sidebar .side-lang-opt:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar .side-lang-opt.active { background: var(--brand-600, #2563eb); color: #fff; font-weight: 600; }
/* Language switcher บนหน้า login (มุมขวาบน) */
.auth-lang { position: absolute; top: 1rem; right: 1.1rem; z-index: 5; display: flex; align-items: center; gap: .3rem;
  background: rgba(255,255,255,.85); backdrop-filter: blur(6px); border: 1px solid var(--border, #e5e7eb); border-radius: 999px; padding: .25rem .5rem; }
.auth-lang > .bi-translate { color: #64748b; font-size: .85rem; }
.auth-lang-opt { padding: .15rem .55rem; border-radius: 999px; font-size: .82rem; color: #475569; text-decoration: none; }
.auth-lang-opt:hover { background: rgba(0,0,0,.05); }
.auth-lang-opt.active { background: var(--brand-600, #2563eb); color: #fff; font-weight: 600; }

.main { flex: 1; margin-left: var(--side-w); min-width: 0; display: flex; flex-direction: column; }

/* ---------- Topbar ---------- */
.topbar {
  height: var(--top-h); background: rgba(255,255,255,.82); backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: .6rem;
  padding: 0 1.1rem; position: sticky; top: 0; z-index: var(--z-top);
}
[data-theme="dark"] .topbar { background: rgba(18,28,48,.82); }
.topbar .menu-toggle { display: none; }
.topbar .top-title { font-weight: var(--fw-bold); font-size: 1rem; color: var(--text); margin: 0; letter-spacing: -.2px; }
.topbar .top-sub { font-size: .72rem; color: var(--muted); }
.topbar-search {
  display: flex; align-items: center; gap: .5rem; background: var(--surface-3); border: 1px solid transparent;
  border-radius: var(--r-pill); padding: .4rem .9rem; color: var(--muted); min-width: 240px; cursor: text;
  transition: border-color var(--t-fast), background var(--t-fast);
  min-height: 40px; /* F-10: was ~22px — meet WCAG 2.5.8 target size (≥24px AA; 40px comfortable) */
}
/* F-10: topbar action buttons (language / user dropdown) — ensure a comfortable target height */
.topbar .btn { min-height: 40px; }
.topbar-search:hover { border-color: var(--border-2); }
/* F-12: show keyboard focus on the search pill (input itself is outline:none) */
.topbar-search:focus-within { border-color: var(--brand); box-shadow: var(--ring); }
[data-theme="dark"] .topbar-search:focus-within { border-color: var(--brand-400); }
.topbar-search input { border: 0; background: transparent; outline: none; font-size: .85rem; color: var(--text); width: 100%; }
.topbar-search kbd { margin-left: auto; }

/* icon button used in topbar */
.icon-btn {
  width: 40px; height: 40px; border-radius: var(--r-sm); border: 1px solid transparent; background: transparent;
  color: var(--text-2); display: inline-grid; place-items: center; font-size: 1.12rem; position: relative;
  transition: background var(--t-fast), color var(--t-fast); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn .dot-badge {
  position: absolute; top: 6px; right: 6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 99px;
  background: var(--danger); color: #fff; font-size: .62rem; font-weight: var(--fw-bold); display: grid; place-items: center;
  border: 2px solid var(--surface);
}

/* ---------- Content + Page header ---------- */
/* F-15: tightened density */
/* full-width บนจอใหญ่ — เดิม cap 1600px ทำให้เหลือขอบว่างซ้าย/ขวาบนจอกว้าง (cap สูงไว้กัน line ยาวเกินบน 4K+) */
.content { padding: 1.1rem 1.5rem 1.75rem; max-width: 2560px; width: 100%; margin: 0 auto; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-head .ph-titles { min-width: 0; }
.page-title { font-weight: var(--fw-bold); font-size: 1.25rem; margin: 0; letter-spacing: -.4px; line-height: 1.25; display: flex; align-items: center; gap: .5rem; }
.page-sub { color: var(--text-2); font-size: .82rem; margin: .2rem 0 0; }
.page-head .ph-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.breadcrumb-mini { font-size: .76rem; color: var(--muted); margin-bottom: .35rem; display: flex; gap: .4rem; align-items: center; }
.breadcrumb-mini a { color: var(--muted); }
.breadcrumb-mini a:hover { color: var(--brand-600); }

/* ---------- Cards ---------- */
.card {
  border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-card);
  background: var(--surface); color: var(--text);
}
.card .card-body { padding: 1rem 1.1rem; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .8rem 1.1rem; border-bottom: 1px solid var(--border);
}
.card-head h2, .card-head h3, .card-head .card-title {
  font-size: .92rem; font-weight: var(--fw-bold); margin: 0; letter-spacing: -.2px; display: flex; align-items: center; gap: .5rem;
}
.card-head .card-sub { font-size: .76rem; color: var(--muted); font-weight: var(--fw-normal); }
.card-hover { transition: transform var(--t), box-shadow var(--t), border-color var(--t); }
.card-hover:hover { transform: translateY(-2px); box-shadow: var(--sh-md); border-color: var(--border-2); }

/* ---------- Stat / KPI cards ---------- */
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--sh-card); padding: .85rem .95rem; position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: .4rem; transition: transform var(--t), box-shadow var(--t), border-color var(--t);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--sh-md); border-color: var(--border-2); }
.stat-card .stat-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.stat-card .stat-value { font-size: 1.45rem; font-weight: var(--fw-black); line-height: 1; letter-spacing: -1px; color: var(--text); }
.stat-card .stat-label { color: var(--text-2); font-size: .76rem; font-weight: var(--fw-medium); }
/* .stat-icon = icon chip ทุกที่ (ไม่จำกัดต้องอยู่ใน .stat-card) → จัดไอคอนกึ่งกลางเสมอ
   เดิม centering ผูกกับ .stat-card .stat-icon ทำให้ chip ที่ใช้เดี่ยว (setup/billing/report ฯลฯ)
   ไอคอนลอยชิดบน-ซ้าย. ย้าย display/centering ออกมาเป็น global, คงขนาดเฉพาะใน .stat-card. */
.stat-icon { display: grid; place-items: center; line-height: 1; flex: 0 0 auto; }
.stat-icon > i, .stat-icon > .bi { display: block; line-height: 1; }
.stat-card .stat-icon {
  width: 38px; height: 38px; border-radius: var(--r-md); font-size: 1.1rem;
}
.stat-trend { display: inline-flex; align-items: center; gap: .2rem; font-size: .72rem; font-weight: var(--fw-bold); padding: .12rem .45rem; border-radius: var(--r-pill); }
/* semantic TEXT tokens are theme-adaptive (light+dark verified) — no per-theme override needed */
.stat-trend.up { color: var(--success-text); background: var(--success-soft); }
.stat-trend.down { color: var(--danger-text); background: var(--danger-soft); }
.stat-trend.flat { color: var(--secondary-text); background: var(--secondary-soft); }
/* KPI tile: tabular numerals for aligned figures. Tiles stay COMPACT and EQUAL — no forced min-height
   or per-tile footer (a sparkline/trend on only some tiles makes the row look uneven + wastes space).
   Equal height comes from identical structure (icon row + value + label) + the grid row stretching cards. */
.stat-card .stat-value { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.stat-card .stat-top { min-height: 38px; }
/* tabular-figures utility — align numbers/money in tables, KPIs, reports (data-precision look) */
.tnum { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* soft tile colors (legacy names kept) */
.tile-primary { background: var(--brand-soft); color: var(--brand-text); }
.tile-success { background: var(--success-soft); color: var(--success-text); }
.tile-warning { background: var(--warning-soft); color: var(--warning-text); }
.tile-danger  { background: var(--danger-soft); color: var(--danger-text); }
.tile-info    { background: var(--info-soft); color: var(--info-text); }
.tile-secondary { background: var(--secondary-soft); color: var(--secondary-text); }
/* A .badge-soft nested inside a .tile-* sits on soft-on-soft (double tint) — drops contrast in dark.
   Give nested badges a solid surface chip so their text stays ≥4.5:1 in both themes. */
:is(.tile-primary,.tile-success,.tile-warning,.tile-danger,.tile-info,.tile-secondary,.accordion-button) .badge-soft { background: var(--surface); }

/* ---------- Buttons (premium overrides on Bootstrap) ---------- */
.btn { font-weight: var(--fw-semibold); border-radius: var(--r-sm); padding: .5rem .95rem; font-size: .875rem; letter-spacing: .1px; transition: all var(--t-fast); display: inline-flex; align-items: center; justify-content: center; gap: .45rem; line-height: 1.2; white-space: nowrap; }
.btn:focus-visible { outline: 2px solid var(--ring-outline); outline-offset: 2px; box-shadow: var(--ring); }
.btn-sm { padding: .35rem .65rem; font-size: .8rem; border-radius: var(--r-xs); }
.btn-lg { padding: .7rem 1.3rem; font-size: 1rem; border-radius: var(--r-md); }
.btn i { font-size: 1.02em; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); box-shadow: 0 2px 6px var(--brand-shadow); }
.btn-primary:hover, .btn-primary:focus { background: var(--brand-700); border-color: var(--brand-700); color: #fff; box-shadow: 0 4px 12px var(--brand-shadow); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-gradient { background: var(--brand-grad); border: 0; color: #fff; box-shadow: 0 4px 14px var(--brand-shadow); }
.btn-gradient:hover { color: #fff; filter: brightness(1.05); transform: translateY(-1px); }
.btn-success { background: var(--success); border-color: var(--success); color: var(--btn-on-bright); }
.btn-danger { background: var(--danger); border-color: var(--danger); color:#fff; }
.btn-warning { background: var(--warning); border-color: var(--warning); color: var(--btn-on-bright); }
.btn-info { background: var(--info); border-color: var(--info); color: var(--btn-on-bright); }
.btn-outline-secondary, .btn-light { border-color: var(--border-2); color: var(--text-2); background: var(--surface); }
.btn-light:hover, .btn-outline-secondary:hover { background: var(--surface-3); color: var(--text); border-color: var(--border-2); }
.btn-ghost { background: transparent; border: 1px solid transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
/* soft button variants */
.btn-soft-primary { background: var(--brand-soft); color: var(--brand-text); border: 1px solid transparent; }
.btn-soft-primary:hover { background: var(--brand-soft-2); color: var(--brand-text); }
.btn-soft-success { background: var(--success-soft); color: var(--success-text); border: 1px solid transparent; }
.btn-soft-danger { background: var(--danger-soft); color: var(--danger-text); border: 1px solid transparent; }
.btn-soft-warning { background: var(--warning-soft); color: var(--warning-text); border: 1px solid transparent; }
.btn-icon { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: var(--r-sm); }
.btn-icon.btn-sm { width: 31px; height: 31px; }
/* floating action button (mobile) */
.fab {
  position: fixed; right: 1.1rem; bottom: 5.2rem; z-index: var(--z-bottomnav); width: 56px; height: 56px; border-radius: var(--r-pill);
  background: var(--brand-grad); color: #fff; border: 0; display: none; place-items: center; font-size: 1.5rem; box-shadow: var(--sh-lg);
}

/* ---------- Forms ---------- */
.form-label { font-size: .82rem; font-weight: var(--fw-semibold); color: var(--text-2); margin-bottom: .35rem; }
.form-control, .form-select {
  border-radius: var(--r-sm); border: 1px solid var(--border-2); padding: .55rem .8rem; font-size: .875rem;
  color: var(--text); background-color: var(--surface); transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.form-control::placeholder { color: var(--muted); }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: var(--ring); }
/* ---------- File inputs: style native picker button with design tokens (fixes light+dark consistency) ---------- */
.form-control[type="file"] { padding: .3rem .55rem; cursor: pointer; line-height: 1.5; }
.form-control[type="file"]::file-selector-button {
  font-weight: var(--fw-semibold); font-size: .82rem; padding: .42rem .9rem; margin: -.3rem .75rem -.3rem -.55rem;
  border: 0; border-right: 1px solid var(--border-2); border-radius: var(--r-sm) 0 0 var(--r-sm);
  background: var(--brand-soft); color: var(--brand-text); cursor: pointer; transition: background var(--t-fast);
}
.form-control[type="file"]::file-selector-button:hover { background: var(--brand-soft-2); }
/* small inputs/selects: ปรับให้สูงเท่า .btn-sm (~31px) เพื่อแถวฟอร์มสม่ำเสมอ (กันปุ่มข้าง input เตี้ย/สูงไม่เท่า) */
.form-control-sm, .form-select-sm { padding: .32rem .62rem; font-size: .8rem; border-radius: var(--r-xs); }
/* select caret: เผื่อ padding-right ให้ลูกศรไม่ทับข้อความ (shorthand padding ด้านบนเขียนทับของ Bootstrap) */
.form-select { padding-right: 2.2rem; background-position: right .7rem center; }
.form-select-sm { padding-right: 1.9rem; background-position: right .55rem center; }
.form-control-sm[type="file"] { padding: .2rem .5rem; }
.form-control-sm[type="file"]::file-selector-button { padding: .26rem .7rem; font-size: .78rem; margin: -.2rem .6rem -.2rem -.45rem; }
/* ปุ่มที่อยู่แถวเดียวกับ input (align-items-end / input-group) ให้ความสูงพอดีกัน */
.btn-icon.btn-sm { width: 31px; height: 31px; }
[data-theme="dark"] .form-control:focus, [data-theme="dark"] .form-select:focus { border-color: var(--brand-400); }
.form-control:disabled, .form-select:disabled { background: var(--surface-3); color: var(--muted); }
.form-text { color: var(--muted); font-size: .76rem; }
.input-icon { position: relative; }
.input-icon > i { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon .form-control { padding-left: 2.3rem; }
.is-invalid ~ .invalid-feedback, .invalid-feedback { color: var(--danger-text); font-size: .76rem; }
.valid-feedback { color: var(--success-text); font-size: .76rem; }
.form-control.is-invalid, .form-select.is-invalid { border-color: var(--danger); }
.form-control.is-valid, .form-select.is-valid { border-color: var(--success); }
/* filter bar */
.filter-bar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: .85rem 1rem; box-shadow: var(--sh-card); }
.filter-bar .fb-item { display: flex; flex-direction: column; gap: .25rem; }
.filter-bar .fb-grow { flex: 1 1 220px; }

/* ตัวกรองเพิ่มเติม (advanced filter panel) — แผงเลื่อนลงแบบมีกรอบ/หัวข้อ/จัดกลุ่มชัด */
.emp-adv-panel { margin-top: .6rem; background: var(--surface-2, var(--surface)); border: 1px solid var(--border); border-radius: var(--r-lg); padding: .9rem 1.1rem 1rem; box-shadow: var(--sh-card); position: relative; }
.emp-adv-panel::before { content: ""; position: absolute; top: -6px; left: 26px; width: 11px; height: 11px; background: var(--surface-2, var(--surface)); border-left: 1px solid var(--border); border-top: 1px solid var(--border); transform: rotate(45deg); } /* ลูกศรชี้ปุ่ม */
.emp-adv-head { display: flex; align-items: center; gap: .45rem; font-weight: 600; font-size: .82rem; color: var(--muted); letter-spacing: .01em; margin-bottom: .7rem; }
.emp-adv-head .bi { color: var(--primary); }
.emp-adv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .75rem 1rem; align-items: end; }
.emp-adv-field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.emp-adv-field-wide { grid-column: span 2; }
.emp-adv-lbl { font-size: .76rem; font-weight: 500; color: var(--muted); margin: 0; }
.emp-adv-checks { display: flex; flex-wrap: wrap; gap: .5rem; }
.emp-adv-chip { display: inline-flex; align-items: center; gap: .45rem; margin: 0; padding: .42rem .7rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); cursor: pointer; font-size: .82rem; transition: border-color .15s var(--ease), background .15s var(--ease); user-select: none; }
.emp-adv-chip:hover { border-color: var(--primary); }
.emp-adv-chip input { margin: 0; cursor: pointer; }
.emp-adv-chip:has(input:checked) { border-color: var(--primary); background: var(--primary-soft, rgba(13,110,253,.08)); color: var(--primary); font-weight: 500; }
/* เลื่อนลงนุ่มนวล (Bootstrap collapse จัดการ height ; เพิ่ม fade ของ panel) */
#empAdvFilters.collapsing .emp-adv-panel, #empAdvFilters.show .emp-adv-panel { animation: hr-fade-up .3s var(--ease) both; }
@media (max-width: 640px) { .emp-adv-field-wide { grid-column: 1 / -1; } }
/* sectioned form */
.form-section { border-top: 1px solid var(--border); padding-top: 1.1rem; margin-top: 1.1rem; }
.form-section:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.form-section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: var(--fw-bold); margin-bottom: .75rem; }
/* stepper */
.stepper { display: flex; gap: .25rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.stepper .step { display: flex; align-items: center; gap: .5rem; padding: .4rem .75rem; border-radius: var(--r-pill); background: var(--surface-3); color: var(--muted); font-size: .8rem; font-weight: var(--fw-semibold); }
.stepper .step .num { width: 22px; height: 22px; border-radius: 50%; background: var(--border-2); color: #fff; display: grid; place-items: center; font-size: .72rem; }
.stepper .step.active { background: var(--brand-soft); color: var(--brand-700); }
.stepper .step.active .num { background: var(--brand); }
.stepper .step.done .num { background: var(--success); }

/* ---------- Tables (premium + responsive card) ---------- */
.table { color: var(--text); margin: 0; --bs-table-bg: transparent; --bs-table-color: var(--text); }
.table > thead th {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  font-weight: var(--fw-bold); border-bottom: 1px solid var(--border); padding: .7rem .85rem; white-space: nowrap; background: var(--surface-2);
}
.table > tbody > tr { border-bottom: 1px solid var(--border); transition: background var(--t-fast); }
.table > tbody > tr:last-child { border-bottom: 0; }
.table > tbody > tr:hover { background: var(--surface-2); }
.table > tbody > td, .table > tbody > tr > td { padding: .7rem .85rem; vertical-align: middle; border: 0; font-size: .875rem; }
/* ตารางกว้างกว่าการ์ด (หลายคอลัมน์ เช่น anti-fraud 9 คอลัมน์) → เลื่อนแนวนอนได้จริง ไม่ตัดคอลัมน์ "จัดการ" (ปุ่มอนุมัติ/ปฏิเสธ).
   overflow-x:auto = เลื่อนเมื่อจำเป็น · overflow-y:hidden = คงมุมโค้ง/เงาการ์ด (หน้าเลื่อนแนวตั้งเองอยู่แล้ว).
   มือถือ (≤767px) ตารางกลายเป็น .table-responsive-cards (block เต็มกว้าง) → ไม่เกิด scroll แนวนอน. */
.table-card-wrap { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-card); overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
/* การ์ดที่เป็น flex column (เช่น มี <nav> pager อยู่ใต้ table-card-wrap) ไม่ให้ scroll-x ของ wrap ดันตัวเอง */
.table-card-wrap > .table { margin-bottom: 0; }
/* คอลัมน์ "จัดการ" ปักขวา (sticky) ในตารางกว้าง (anti-fraud) — เห็นปุ่มอนุมัติ/ปฏิเสธเสมอแม้เลื่อนแนวนอน (เดสก์ท็อป ≥768px) */
@media (min-width: 768px) {
  .af-alerts-table .af-col-actions { position: sticky; right: 0; z-index: 2; background: var(--surface); box-shadow: -8px 0 8px -8px rgba(15, 23, 42, .18); }
  .af-alerts-table thead .af-col-actions { background: var(--surface-2); }
  .af-alerts-table > tbody > tr:hover .af-col-actions { background: var(--surface-2); }
  /* แถวที่เลือก (bulk): คอลัมน์ sticky ต้อง tint ตามแถว ไม่งั้นดู 2 โทน (พื้น surface ทับ brand-soft) */
  .af-alerts-table > tbody > tr.af-selected .af-col-actions { background: var(--brand-soft); }
  /* ปุ่ม/แบดจ์ในคอลัมน์จัดการ = จัดชิดขวา + ห่อบรรทัดได้เมื่อจอแคบ (กันคอลัมน์ดันความกว้างคงที่ 400px → ตารางล้นแนวนอน) */
  .af-alerts-table .af-col-actions {
    max-width: 14rem; white-space: normal;
  }
  .af-alerts-table td.af-col-actions > * { display: inline-flex; }
  .af-alerts-table td.af-col-actions {
    display: flex; flex-wrap: wrap; gap: .3rem; justify-content: flex-end; align-items: center;
  }
  .af-alerts-table .af-col-actions .btn { white-space: nowrap; }
  /* แบดจ์ "ตอกผ่าน-ติดธง (อนุญาตแล้ว)" ยาว → ห่อได้ + ขึ้นเต็มบรรทัด กันดันคอลัมน์ */
  .af-alerts-table .af-col-actions .badge-soft { white-space: normal; text-align: left; }
  /* คอลัมน์ "เหตุผล" = เนื้อหาสำคัญสุด → ให้กว้างสุด (ดูดพื้นที่ที่เหลือ) + ตัด 2 บรรทัด + tooltip ดูเต็ม.
     คอลัมน์อื่นกำหนดความกว้างพอดีเนื้อหา (พนักงาน/ความเสี่ยง/ผู้อนุมัติ) เพื่อปล่อยที่ให้เหตุผล (7 คอลัมน์ ลดจาก 9) */
  .af-alerts-table .af-th-emp    { width: 9.5rem; }
  .af-alerts-table .af-th-time   { width: 6rem; }
  .af-alerts-table .af-th-risk   { width: 8.5rem; white-space: nowrap; }
  .af-alerts-table .af-th-reason { width: auto; min-width: 10rem; }
  .af-alerts-table .af-cell-reason { white-space: normal; }
  /* คอลัมน์สถานะ: แบดจ์ "ตอกผ่าน-ติดธง" ยาวสุด → คุมความกว้างคอลัมน์ให้พอดี (badge คง nowrap อ่านง่าย ไม่หักคำไทย) */
  .af-alerts-table .af-cell-status { width: 7rem; }
  .af-alerts-table .af-cell-status .badge-soft { white-space: nowrap; }
  /* เวลา: ไอคอนนาฬิกาไม่ดันความกว้าง + ระยะกระชับ (ลดคอลัมน์เวลาจาก ~121px) */
  .af-alerts-table .af-cell-time .bi-clock { margin-right: .2rem !important; }
  /* ผู้อนุมัติ/เวลา: จำกัดความกว้าง กันคอลัมน์ดันตารางล้น (ชื่อ/เหตุผลยาว) */
  .af-alerts-table .af-cell-approver { max-width: 11rem; }
  /* เวลา: วันที่ + เวลา ขึ้น 2 บรรทัด (คอลัมน์แคบลง ไม่ดันตารางล้น) */
  .af-alerts-table .af-cell-time { line-height: 1.3; }
}
/* เหตุผล: ตัดสูงสุด 2 บรรทัด แล้ว … (อ่านเต็มได้ที่ title/tooltip) — กันแถวสูงผิดปกติเมื่อข้อความยาว */
.af-alerts-table .af-reason-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.35;
  word-break: break-word;
}
.af-alerts-table .af-risk-score { font-weight: 600; opacity: .85; }
.table-sticky thead th { position: sticky; top: var(--top-h); z-index: 2; }
/* คลิกหัวคอลัมน์เพื่อจัดเรียง (server-side) — tables.js + sort_th() */
.table > thead th.th-sort { cursor: pointer; user-select: none; transition: color var(--t-fast), background var(--t-fast); }
.table > thead th.th-sort:hover, .table > thead th.th-sort:focus-visible { color: var(--text); background: var(--surface-3); }
/* a11y (WCAG 2.4.7): keyboard focus ต้องเห็นชัด — ใส่ ring ตอน focus-visible (ไม่ใช่ outline:none) */
.table > thead th.th-sort:focus-visible { outline: 2px solid var(--ring-outline); outline-offset: -2px; }
.table > thead th.th-sort .sort-ind { font-size: .7rem; margin-left: .15rem; }
.table > thead th.th-sort .sort-ind-idle { opacity: 0; transition: opacity var(--t-fast); }
.table > thead th.th-sort:hover .sort-ind-idle, .table > thead th.th-sort:focus-visible .sort-ind-idle { opacity: .5; }
.table > thead th.th-sort[aria-sort="ascending"], .table > thead th.th-sort[aria-sort="descending"] { color: var(--brand-text); }
/* ── Anti-fraud redesign (action-first + unified filter + bulk) — scope ด้วย prefix af- กันชนทั่ว project ── */
/* unified filter bar: pinned ใต้ header global (≥md sticky) — แหล่งความจริงเดียวของช่วงวัน/บริษัท/สาขา/ค้นหา */
.af-filterbar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-card); padding: .7rem .85rem; }
@media (min-width: 641px) { .af-filterbar { position: sticky; top: var(--top-h, .5rem); z-index: 5; } }
@media (max-width: 640px) { .af-filterbar { position: static; } }
.af-filterbar .af-fb-date { width: 8.5rem; }
.af-filterbar .af-fb-presets .btn.active { background: var(--brand-soft); color: var(--brand-text); border-color: transparent; }
/* bulk action bar — โผล่เมื่อเลือก ≥1 แถว, อยู่บนสุดของ card-body (เหนือตาราง) เห็นทันทีที่เลือก
   เดสก์ท็อป = static (ไม่ sticky): กัน stacking ชนกับ unified filter bar (sticky top คนละ context)
   มือถือ = sticky bottom (กฎ ≤640px ด้านล่าง) เผื่อรายการยาว */
.af-bulk-bar { display: none; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
  background: var(--brand-soft); border: 1px solid var(--brand-400, #818cf8); border-radius: var(--r-md);
  padding: .55rem .8rem; box-shadow: var(--sh-card); }
.af-bulk-bar.show { display: flex; }
.af-bulk-bar .af-bulk-count { font-weight: var(--fw-semibold); color: var(--text); }
/* แถวที่เลือก = tint (dark-safe ผ่าน token) */
.af-alerts-table > tbody > tr.af-selected > td { background: var(--brand-soft); }
/* batch mode active → จาง/ปิด inline action ต่อแถว (กันสับสน 2 ทางเลือก) */
.af-alerts-table.af-batch-active .af-col-actions .btn,
.af-alerts-table.af-batch-active .af-col-actions form { opacity: .4; pointer-events: none; }
.af-alerts-table .af-row-check { cursor: pointer; }
/* healthy / empty state เชิงบวก (icon ใหญ่สีเขียว token) */
.af-empty-healthy { text-align: center; padding: 2.5rem 1rem; }
.af-empty-healthy .af-eh-ico { font-size: 2.4rem; width: 76px; height: 76px; display: flex; align-items: center; justify-content: center; margin: 0 auto .9rem; border-radius: 50%; color: var(--success-text); background: var(--success-soft); }
.af-empty-healthy .af-eh-title { font-weight: var(--fw-bold); margin-bottom: .25rem; }
/* secondary tabs: scroll แนวนอนบน mobile + map สูงลดลง */
@media (max-width: 640px) {
  .af-monitor-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .af-monitor-tabs .nav-link { white-space: nowrap; }
  #afMap { height: 300px !important; }
  /* bulk bar บน mobile = sticky bottom เหนือ bottom-nav + safe-area (รายการ card ยาว → ปุ่มลอยตามเสมอ) */
  .af-bulk-bar { position: sticky; z-index: 6; bottom: calc(var(--bottom-nav-h, 56px) + env(safe-area-inset-bottom, 0px) + .5rem); }
}
/* ── Anti-fraud item 1: "ทำไมถึงเสี่ยง" toggle + signal chips (กาง/ยุบ) ── */
.af-why-toggle {
  display: inline-flex; align-items: center; gap: .3rem; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: var(--r-pill); padding: .15rem .55rem; font-size: .72rem; font-weight: var(--fw-semibold);
  line-height: 1.5; transition: all var(--t-fast) var(--ease);
}
.af-why-toggle:hover { border-color: var(--brand-400, #818cf8); background: var(--brand-soft); }
.af-why-toggle .af-why-count { color: var(--muted); font-weight: var(--fw-semibold); }
.af-why-toggle .af-why-caret { transition: transform var(--t-fast) var(--ease); font-size: .85em; }
.af-why-toggle.af-why-open .af-why-caret { transform: rotate(180deg); }
/* สีปุ่มสื่อความรุนแรงสูงสุด (icon+text+สี — ไม่พึ่งสีเดียว) */
.af-why-toggle.af-why-danger  { border-color: var(--danger-text); color: var(--danger-text); background: var(--danger-soft); }
.af-why-toggle.af-why-warning { border-color: var(--warning-text); color: var(--warning-text); background: var(--warning-soft); }
.af-why-toggle.af-why-danger .af-why-count,
.af-why-toggle.af-why-warning .af-why-count { color: inherit; opacity: .8; }
.af-signals { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .4rem; }
.af-signals .af-signal { white-space: normal; text-align: left; max-width: 100%; }
.af-signals .af-signal-detail { color: var(--muted); font-size: .92em; font-weight: 500; }

/* ── Anti-fraud item 2: clickable employee name + drill-down drawer ── */
.af-emp-link {
  border: 0; background: none; padding: 0; text-align: left; color: var(--brand-text);
  cursor: pointer; font: inherit; font-weight: var(--fw-semibold);
  display: inline-flex; align-items: center; gap: .1rem; max-width: 100%;
}
.af-emp-link:hover, .af-emp-link:focus-visible { color: var(--brand); text-decoration: underline; }
.af-emp-link .af-emp-arrow { opacity: 0; transform: translateX(-3px); transition: all var(--t-fast) var(--ease); font-size: 1.1em; }
.af-emp-link:hover .af-emp-arrow, .af-emp-link:focus-visible .af-emp-arrow { opacity: .7; transform: translateX(0); }
.af-drawer { width: 420px; max-width: 92vw; }
.af-drawer .af-drawer-avatar { width: 38px; height: 38px; flex: 0 0 38px; }
.af-drawer .min-w-0 { min-width: 0; }
/* KPI ย่อ */
.af-dd-kpi { border: 1px solid var(--border); border-radius: var(--r-md); padding: .55rem .6rem; text-align: center; background: var(--surface-2); height: 100%; }
.af-dd-kpi .af-dd-kpi-val { font-size: 1.25rem; font-weight: var(--fw-bold); line-height: 1.1; }
.af-dd-kpi .af-dd-kpi-lbl { font-size: .72rem; color: var(--muted); margin-top: .15rem; }
.af-dd-kpi.af-dd-ok   .af-dd-kpi-val { color: var(--success-text); }
.af-dd-kpi.af-dd-warn .af-dd-kpi-val { color: var(--warning-text); }
.af-dd-kpi.af-dd-bad  .af-dd-kpi-val { color: var(--danger-text); }
/* timeline การตอก */
.af-timeline { position: relative; padding-left: 1.1rem; }
.af-timeline::before { content: ""; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.af-tl-item { position: relative; padding: 0 0 .85rem .35rem; }
.af-tl-item:last-child { padding-bottom: 0; }
.af-tl-dot { position: absolute; left: -1.1rem; top: .25rem; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 2px currentColor; }
.af-tl-dot.af-tl-in  { color: var(--success-text); background: var(--success-text); }
.af-tl-dot.af-tl-out { color: var(--secondary-text, var(--muted)); background: var(--secondary-text, var(--muted)); }
.af-tl-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.af-tl-dir { font-weight: var(--fw-semibold); }
.af-tl-dir.af-tl-in  { color: var(--success-text); }
.af-tl-dir.af-tl-out { color: var(--muted); }
.af-tl-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .6rem; margin-top: .25rem; }
.af-tl-dist { font-size: .78rem; display: inline-flex; align-items: center; gap: .2rem; }
/* exceptions ล่าสุด */
.af-drawer-ex .af-dd-exrow { border: 1px solid var(--border); border-radius: var(--r-md); padding: .6rem .7rem; margin-bottom: .5rem; background: var(--surface-2); }
.af-drawer-ex .af-dd-exrow:last-child { margin-bottom: 0; }
@media (max-width: 640px) { .af-drawer { width: 100vw; } }

/* ระหว่าง AJAX swap (tables.js) — หรี่ตาราง + กันคลิกซ้ำ ชั่วครู่ */
.table-busy { opacity: .5; pointer-events: none; transition: opacity .12s ease; }
/* แถวเงินเดือนที่ควรตรวจ (สุทธิ/รายได้ผิดปกติ) — เชื่อมกับ AI anomaly */
.table > tbody > tr.pr-row-flag > td { background: var(--warning-soft); }

/* ── Breadcrumb (navigation context) — บอกว่าอยู่เมนูไหน/เข้าทางไหน ── */
.hr-breadcrumb { margin: 0 0 1rem; font-size: .82rem; }
.hr-breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .15rem; margin: 0; padding: 0; }
.hr-breadcrumb li { display: inline-flex; align-items: center; gap: .15rem; }
.hr-breadcrumb a { color: var(--muted); text-decoration: none; padding: .15rem .3rem; border-radius: var(--radius-sm, 6px); transition: color var(--t-fast), background var(--t-fast); }
.hr-breadcrumb a:hover, .hr-breadcrumb a:focus-visible { color: var(--brand-text); background: var(--surface-3); outline: none; }
.hr-breadcrumb li[aria-current="page"] > span { color: var(--text); font-weight: 600; padding: .15rem .3rem; }
.hr-breadcrumb li > span { color: var(--muted); padding: .15rem .3rem; }
.hr-breadcrumb .hr-bc-sep { font-size: .7rem; color: var(--muted); opacity: .6; margin: 0 .05rem; }

/* ── Mini sidebar (ย่อเหลือไอคอน, เฉพาะ desktop ≥992px) — มี tooltip ข้อความตอน hover ── */
@media (min-width: 992px) {
  .sidebar { transition: transform var(--t) var(--ease), width var(--t) var(--ease); }
  .main { transition: margin-left var(--t) var(--ease); }
  html.sidebar-mini .sidebar { width: var(--side-w-collapsed); }
  html.sidebar-mini .main { margin-left: var(--side-w-collapsed); }
  /* ซ่อนข้อความ เหลือไอคอน */
  html.sidebar-mini .sidebar .brand-name,
  html.sidebar-mini .sidebar a.nav-item span,
  html.sidebar-mini .sidebar .nav-group-toggle,
  html.sidebar-mini .sidebar .side-lang,
  html.sidebar-mini .sidebar .nav-badge,
  html.sidebar-mini .sidebar .side-mode-toggle span,
  html.sidebar-mini .sidebar .side-foot .nav-item span { display: none; }
  /* แสดงทุกกลุ่มแบบ flat (ไม่ยุบ) ในโหมดไอคอน */
  html.sidebar-mini .sidebar .nav-group { grid-template-rows: 1fr !important; }
  /* จัดไอคอนกึ่งกลาง */
  html.sidebar-mini .sidebar a.nav-item,
  html.sidebar-mini .sidebar .side-mode-toggle,
  html.sidebar-mini .sidebar .side-foot .nav-item { justify-content: center; padding-left: .5rem; padding-right: .5rem; }
  html.sidebar-mini .sidebar a.nav-item i { width: auto; font-size: 1.2rem; }
  html.sidebar-mini .sidebar .brand { justify-content: center; gap: 0; }
}
/* ปุ่มย่อ sidebar — โชว์เฉพาะ desktop (มือถือใช้ hamburger) */
.sidebar-collapse-toggle { display: none; }
@media (min-width: 992px) { .sidebar-collapse-toggle { display: inline-flex; } }
/* tooltip ลอย (position:fixed → ไม่โดน sidebar overflow ตัด) */
.hr-mini-tip { position: fixed; transform: translateY(-50%); background: #1f2937; color: #fff; padding: .35rem .65rem; border-radius: 7px; white-space: nowrap; z-index: 1200; pointer-events: none; opacity: 0; transition: opacity .12s ease; font-size: .82rem; box-shadow: 0 8px 24px rgba(0,0,0,.3); border: 1px solid rgba(255,255,255,.12); }
.hr-mini-tip.show { opacity: 1; }

/* ── ปฏิทินเข้า-ออกงาน (attendance report) ── */
.att-cal-head { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 6px; }
.att-cal-head > div { text-align: center; font-size: .75rem; color: var(--muted); font-weight: 600; }
.att-cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.att-cell { min-height: 80px; border: 1px solid var(--border); border-radius: 8px; padding: 5px 6px; background: var(--surface-2); font-size: .72rem; line-height: 1.35; }
.att-cell.att-empty { background: transparent; border: none; }
.att-cell[data-st="present"] { border-left: 3px solid var(--success-text); }
.att-cell[data-st="late"] { border-left: 3px solid var(--warning-text); }
.att-cell[data-st="leave"] { border-left: 3px solid var(--info-text); }
.att-cell[data-st="none"] { opacity: .55; }
.att-cell .att-leave { color: var(--info-text); font-weight: 600; }
.att-cell .att-day { font-weight: 700; color: var(--text); margin-bottom: 2px; }
.att-cell .att-in { color: var(--success-text); }
.att-cell .att-out { color: var(--info-text); }
.att-cell .att-hr { color: var(--muted); }
.att-cell .att-late { color: var(--warning-text); }

/* ── Who's-in board (รายงานเข้า-ออกงาน รายวันทั้งบริษัท) ── */
.wi-sum { flex-direction: row !important; align-items: center; gap: .6rem; cursor: pointer; border: 1px solid var(--border); }
.wi-sum .stat-ico { width: 38px; height: 38px; border-radius: var(--r-md); display: grid; place-items: center; font-size: 1.1rem; flex: 0 0 auto; }
.wi-sum .stat-meta { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.wi-sum.active { border-color: var(--brand-600); box-shadow: 0 0 0 2px var(--brand-soft) inset; }
.wi-ava { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-text); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .78rem; flex: 0 0 auto; }
.wi-late { color: var(--warning-text); font-size: .7rem; font-weight: 600; white-space: nowrap; }
.wi-badge { display: inline-flex; align-items: center; gap: .32rem; padding: .2rem .55rem; border-radius: var(--r-pill); font-size: .72rem; font-weight: 600; white-space: nowrap; }
.wi-badge .dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
.wi-st-present { background: var(--success-soft); color: var(--success-text); } .wi-st-present .dot { background: var(--success-text); }
.wi-st-late { background: var(--warning-soft); color: var(--warning-text); } .wi-st-late .dot { background: var(--warning-text); }
.wi-st-working { background: var(--info-soft); color: var(--info-text); } .wi-st-working .dot { background: var(--info-text); animation: wiPulse 1.4s ease-in-out infinite; }
.wi-st-leave { background: var(--brand-soft); color: var(--brand-text); } .wi-st-leave .dot { background: var(--brand-text); }
.wi-st-absent { background: var(--surface-3); color: var(--muted); } .wi-st-absent .dot { background: var(--muted); }
@keyframes wiPulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* ── ปฏิทินทีม (multi-person month matrix) ── */
.wi-mx-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.wi-mx { border-collapse: separate; border-spacing: 0; font-size: .72rem; width: 100%; }
.wi-mx th, .wi-mx td { text-align: center; padding: 0; }
.wi-mx thead th { position: sticky; top: 0; z-index: 2; background: var(--surface); color: var(--muted); font-weight: 600; min-width: 32px; padding: 4px 0; border-bottom: 2px solid var(--border); }
.wi-mx .wi-mx-emp { position: sticky; left: 0; z-index: 3; background: var(--surface); text-align: left; min-width: 180px; max-width: 180px; padding: 6px 8px; border-right: 2px solid var(--border); }
.wi-mx thead .wi-mx-emp { z-index: 4; }
.wi-mx tbody tr { cursor: pointer; }
.wi-mx tbody tr:hover td { background: var(--surface-2); }
.wi-mx tbody tr:hover .wi-mx-emp { background: var(--brand-soft); }
.wi-mx-cell { min-width: 32px; height: 38px; border-bottom: 1px solid var(--border); border-left: 1px solid var(--border); }
.wi-mx-wknd { background: color-mix(in srgb, var(--surface-3) 50%, transparent); }
.wi-mx-d { display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 22px; padding: 0 3px; border-radius: 5px; font-size: .62rem; font-weight: 700; line-height: 1; vertical-align: middle; }
.wi-mx-d:empty { min-width: 14px; height: 14px; border-radius: 4px; }
.wi-d-present { background: var(--success-soft); color: var(--success-text); border: 1px solid var(--success-text); }
.wi-d-late { background: var(--warning-soft); color: var(--warning-text); border: 1px solid var(--warning-text); }
.wi-d-leave { background: var(--info-soft); color: var(--info-text); border: 1px solid var(--info-text); }
/* ไฮไลต์คอลัมน์ "วันนี้" + คอลัมน์สรุป "มากี่วัน" */
.wi-mx .wi-mx-today { background: var(--brand-soft); }
.wi-mx thead th.wi-mx-today { color: var(--brand-text); box-shadow: inset 0 -2px 0 var(--brand-600); }
.wi-mx .wi-mx-sum { position: sticky; right: 0; z-index: 2; background: var(--surface); min-width: 40px; border-left: 2px solid var(--border); font-weight: 700; }
.wi-mx thead .wi-mx-sum { z-index: 4; color: var(--muted); }
.wi-mx tbody tr:hover .wi-mx-sum { background: var(--surface-2); }
.wi-mx .wi-mx-sumv { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 20px; padding: 0 5px; border-radius: var(--r-pill); background: var(--success-soft); color: var(--success-text); font-size: .68rem; }
/* board: sticky thead เมื่อเลื่อน */
#arBoardTable thead th { position: sticky; top: 0; z-index: 1; background: var(--surface); }
@media (max-width: 575.98px) { .att-cell { min-height: 58px; font-size: .62rem; padding: 3px 4px; } }
.table > tbody > tr.pr-row-flag:hover > td { background: var(--warning-soft); }
.row-actions { display: inline-flex; gap: .25rem; opacity: .55; transition: opacity var(--t-fast); }
tr:hover .row-actions { opacity: 1; }
/* อุปกรณ์สัมผัส (ไม่มี hover) → แสดงปุ่ม action เต็มเสมอ (กันปุ่มจางบนแท็บเล็ต/มือถือ) */
@media (hover: none) { .row-actions { opacity: 1; } }
/* กล่องยืนยัน (HR.confirm) — สวยในธีม โชว์ชื่อรายการเด่น */
.hr-confirm-ic { font-size: 2.3rem; line-height: 1; color: var(--danger, #e5484d); }
.hr-confirm-name { font-size: 1.05rem; color: var(--text); word-break: break-word; }
.hr-confirm-msg { color: var(--muted); }

/* ---------- Avatars ---------- */
.avatar { width: 38px; height: 38px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: var(--fw-bold); font-size: .85rem; color: #fff; background: var(--brand); flex: 0 0 auto; text-transform: uppercase; }
.avatar-sm { width: 30px; height: 30px; font-size: .72rem; }
.avatar-lg { width: 52px; height: 52px; font-size: 1.1rem; }
/* avatar bg: เข้มพอให้ตัวอักษรขาว ≥4.5:1 (WCAG AA) — เดิม -600 บางสีตก (3.1-3.8) */
.avatar.a1,.dir-avatar-ph.a1{background:#4338ca}.avatar.a2,.dir-avatar-ph.a2{background:#0e7490}.avatar.a3,.dir-avatar-ph.a3{background:#047857}.avatar.a4,.dir-avatar-ph.a4{background:#b45309}.avatar.a5,.dir-avatar-ph.a5{background:#be123c}.avatar.a6,.dir-avatar-ph.a6{background:#6d28d9}
.media-row { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.media-row .mr-title { font-weight: var(--fw-semibold); color: var(--text); line-height: 1.2; }
.media-row .mr-sub { font-size: .76rem; color: var(--muted); }

/* ---------- Badges / status ---------- */
.badge-soft { font-weight: var(--fw-semibold); padding: .32em .7em; border-radius: var(--r-pill); font-size: .74rem; display: inline-flex; align-items: center; gap: .35em; line-height: 1.4; white-space: nowrap; }
.badge-soft .s-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
/* Semantic badge text uses theme-adaptive --*-text tokens — verified WCAG-AA on BOTH light & dark
   soft-tints (replaces former F-19 light-only overrides; dark variants in theme.css dark block). */
.badge-low, .badge-active, .badge-success, .badge-paid { background: var(--success-soft); color: var(--success-text); }
.badge-medium, .badge-pending, .badge-warning, .badge-issued { background: var(--warning-soft); color: var(--warning-text); }
.badge-high, .badge-danger, .badge-overdue, .badge-suspended { background: var(--danger-soft); color: var(--danger-text); }
.badge-info { background: var(--info-soft); color: var(--info-text); }
.badge-neutral, .badge-void, .badge-draft { background: var(--secondary-soft); color: var(--secondary-text); }
.badge-scope-branch  { background: var(--brand-soft); color: var(--brand-text); }
.badge-scope-tenant  { background: var(--secondary-soft); color: var(--secondary-text); }
.badge-scope-company { background: var(--brand-soft-2); color: var(--brand-text); }
[data-theme="dark"] .badge-scope-company { background: var(--brand-soft); } /* .24 tint too saturated for brand-text in dark (4.3:1) → .16 = 4.67:1 */
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .28rem .65rem; border-radius: var(--r-pill); background: var(--surface-3); color: var(--text-2); font-size: .76rem; font-weight: var(--fw-semibold); }
.kbd { background: var(--surface-3); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: var(--r-xs); padding: .05rem .4rem; font-size: .72rem; color: var(--text-2); font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; }

/* ---------- States: empty / loading / error ---------- */
.state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.state i, .state .state-ico { font-size: 2.1rem; display: flex; align-items: center; justify-content: center; margin: 0 auto .8rem; width: 72px; height: 72px; border-radius: 50%; color: var(--brand-text, #4f46e5); background: radial-gradient(circle at 50% 40%, var(--brand-soft), var(--surface-3)); box-shadow: 0 0 0 6px var(--surface-2); }
.state .state-title { font-weight: var(--fw-bold); color: var(--text-2); font-size: 1rem; margin-bottom: .25rem; }
.state .state-sub { font-size: .82rem; }
.skeleton { background: linear-gradient(90deg, var(--surface-3) 25%, var(--border) 37%, var(--surface-3) 63%); background-size: 400% 100%; animation: hr-shimmer 1.3s ease infinite; border-radius: var(--r-xs); height: 14px; }
@keyframes hr-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.is-loading { position: relative; pointer-events: none; }
.is-loading::after { content: ""; position: absolute; inset: 0; background: rgba(255,255,255,.55); border-radius: inherit; }
[data-theme="dark"] .is-loading::after { background: rgba(11,17,32,.5); }
.spinner-ring { width: 1.1em; height: 1.1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: hr-spin .7s linear infinite; }
@keyframes hr-spin { to { transform: rotate(360deg); } }

/* ---------- Table preload: skeleton loader (มาตรฐานทั้งโปรเจกต์ — แทน spinner วงกลม) ----------
   จำลองโครงตาราง + shimmer ตามธีม + แถบ brand เลื่อนด้านบน + stagger ให้ดูมีชีวิตชีวา
   ใช้ตัวแปรธีมล้วน → ตาม brand/สี/dark ที่ออกแบบไว้อัตโนมัติ */
.tbl-skel { position: absolute; inset: 0; z-index: 4; background: var(--surface); border-radius: inherit; padding: .65rem .85rem; overflow: hidden; display: flex; flex-direction: column; gap: .35rem; animation: tblSkelIn .16s ease both; }
@keyframes tblSkelIn { from { opacity: 0; } to { opacity: 1; } }
.tbl-skel-bar { position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, transparent 0%, color-mix(in srgb, var(--hr-primary) 35%, transparent) 30%, var(--hr-primary) 50%, color-mix(in srgb, var(--hr-primary) 35%, transparent) 70%, transparent 100%); background-size: 45% 100%; background-repeat: no-repeat; animation: tblSkelBar 1.1s ease-in-out infinite; }
@keyframes tblSkelBar { 0% { background-position: -45% 0; } 100% { background-position: 145% 0; } }
.tbl-skel-row { display: flex; align-items: center; gap: 1.1rem; padding: .62rem .35rem; border-bottom: 1px solid var(--border); }
.tbl-skel-row:first-of-type { border-bottom: 2px solid var(--border); padding-top: .5rem; } /* แถวหัวตาราง */
.tbl-skel-row:last-child { border-bottom: 0; }
.tbl-skel-cell { height: 12px; border-radius: 7px; background: linear-gradient(90deg, var(--surface-3) 25%, color-mix(in srgb, var(--hr-primary) 13%, var(--surface-3)) 50%, var(--surface-3) 75%); background-size: 220% 100%; animation: tblSkelShim 1.3s ease-in-out infinite; }
@keyframes tblSkelShim { 0% { background-position: 220% 0; } 100% { background-position: -220% 0; } }
.tbl-skel-cell.w40 { flex: 0 0 7%; } .tbl-skel-cell.w55 { flex: 1 1 15%; } .tbl-skel-cell.w70 { flex: 1 1 22%; } .tbl-skel-cell.w80 { flex: 1 1 27%; }
.tbl-skel-row:nth-child(2) .tbl-skel-cell { animation-delay: .05s; }
.tbl-skel-row:nth-child(3) .tbl-skel-cell { animation-delay: .1s; }
.tbl-skel-row:nth-child(4) .tbl-skel-cell { animation-delay: .15s; }
.tbl-skel-row:nth-child(5) .tbl-skel-cell { animation-delay: .2s; }
.tbl-skel-row:nth-child(6) .tbl-skel-cell { animation-delay: .25s; }
.tbl-skel-row:nth-child(7) .tbl-skel-cell { animation-delay: .3s; }
.tbl-skel-row:nth-child(8) .tbl-skel-cell { animation-delay: .35s; }
.is-loading > .tbl-skel ~ ::after, .is-loading:has(.tbl-skel)::after { display: none; } /* ไม่ต้องซ้อน overlay ขาว เพราะ skeleton ทึบแล้ว */
@media (prefers-reduced-motion: reduce) { .tbl-skel-cell, .tbl-skel-bar { animation: none; } }

/* Drawer รายชื่อ "ยังไม่เข้างาน" (หน้า attendance) */
.att-absent-list { overflow-y: auto; }
.att-absent-row { border-bottom: 1px solid var(--border); }
.att-absent-row:last-child { border-bottom: 0; }
.att-ava { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: .85rem; color: var(--hr-primary); background: color-mix(in srgb, var(--hr-primary) 14%, var(--surface)); }

/* Leave "who is out" chips (manager view บนหน้า /leave) */
.who-out-chip { border: 1px solid var(--border); border-radius: 999px; padding: .3rem .7rem; background: var(--surface-2); font-size: .85rem; }
.who-out-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }

/* Attendance insight card (on-time% + top-late + by-branch) */
.att-ins-rate { background: color-mix(in srgb, var(--hr-primary) 7%, var(--surface)); border: 1px solid var(--border); border-radius: var(--r-md); padding: 1rem .75rem; }
.att-ins-pct { font-size: 2.4rem; font-weight: 700; line-height: 1.05; color: var(--hr-primary); font-variant-numeric: tabular-nums; }
.att-toplate { display: flex; flex-direction: column; gap: .25rem; max-height: 200px; overflow-y: auto; }
.att-toplate-row { display: flex; align-items: center; gap: .5rem; width: 100%; text-align: left; padding: .35rem .5rem; border: 0; border-radius: var(--r-sm); background: transparent; color: inherit; cursor: pointer; }
.att-toplate-row:hover { background: var(--surface-2); }
.att-br-row .att-br-name { flex: 0 0 28%; }
.att-br-bar { height: 8px; border-radius: 5px; background: var(--surface-3); overflow: hidden; }
.att-br-bar > span { display: block; height: 100%; border-radius: 5px; background: var(--hr-primary); }
.att-br-val { min-width: 6.5rem; text-align: right; }
.att-view-chip { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.att-view-chip .att-view-apply { border: 0; background: transparent; color: inherit; font-size: .8rem; padding: .15rem .6rem; cursor: pointer; }
.att-view-chip .att-view-apply:hover { color: var(--hr-primary); }
.att-view-chip .att-view-del { border: 0; background: transparent; color: var(--muted); padding: .15rem .45rem .15rem .1rem; cursor: pointer; line-height: 1; }
.att-view-chip .att-view-del:hover { color: var(--danger); }

/* ---------- Progress / ring ---------- */
.progress-soft { height: 8px; border-radius: 99px; background: var(--c-track); overflow: hidden; }
.progress-soft > span { display: block; height: 100%; border-radius: 99px; background: var(--brand); }
.ring-stat { --val: 0; width: 116px; height: 116px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--brand) calc(var(--val)*1%), var(--c-track) 0); }
.ring-stat .ring-in { width: 84px; height: 84px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-weight: var(--fw-black); font-size: 1.4rem; }

/* ---------- Chart card ---------- */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap.h-sm { height: 220px; }
.chart-wrap.h-md { height: 300px; }
.chart-wrap.h-lg { height: 360px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: .85rem; }
.chart-legend .lg-item { display: inline-flex; align-items: center; gap: .4rem; font-size: .78rem; color: var(--text-2); }
.chart-legend .lg-dot { width: 10px; height: 10px; border-radius: 3px; }

/* ---------- List rows / activity ---------- */
.list-row { display: flex; align-items: center; gap: .75rem; padding: .7rem .25rem; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.list-row .lr-body { flex: 1; min-width: 0; }
.list-row .lr-title { font-weight: var(--fw-semibold); font-size: .88rem; }
.list-row .lr-sub { font-size: .76rem; color: var(--muted); }
.timeline { position: relative; padding-left: 1.4rem; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.timeline .tl-item { position: relative; padding: 0 0 1rem .25rem; }
.timeline .tl-item::before { content: ""; position: absolute; left: -1.18rem; top: 4px; width: 11px; height: 11px; border-radius: 50%; background: var(--brand); border: 2px solid var(--surface); }

/* ---------- Quick action card ---------- */
.qa-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)); gap: .5rem; }
.qa-card { display: flex; flex-direction: column; gap: .45rem; align-items: flex-start; padding: .7rem .75rem; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); color: var(--text); transition: all var(--t-fast); }
.qa-card:hover { border-color: var(--brand-400); background: var(--brand-soft); color: var(--brand-700); transform: translateY(-2px); box-shadow: var(--sh-sm); }
.qa-card i { font-size: 1.15rem; }
.qa-card .qa-label { font-size: .82rem; font-weight: var(--fw-semibold); }

/* ---------- Clock-in big button ---------- */
.clock-btn {
  width: 200px; height: 200px; border-radius: 50%; border: none; color:#fff;
  font-size: 1.2rem; font-weight: var(--fw-bold); box-shadow: 0 18px 38px var(--brand-shadow);
  background: radial-gradient(circle at 32% 28%, var(--brand-500), var(--brand-700)); transition: transform var(--t-fast), box-shadow var(--t-fast);
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem;
}
.clock-btn:hover { transform: scale(1.02); }
.clock-btn:active { transform: scale(.97); }
.clock-btn.out { background: radial-gradient(circle at 32% 28%, var(--danger, #fb7185), var(--danger-700, #be123c)); box-shadow: 0 18px 38px rgba(225,29,72,.36); }
/* มือถือ: ลดขนาด + 2 ปุ่มแนวนอนพอดีจอเดียว (เดิม 200px×2 ล้นจอ → wrap → ปุ่มออกงานถูก bottom nav บัง)
   138px×2 + gap เล็ก (view ใช้ gap-2 gap-sm-*) พอดีแม้จอ 360px — ยืนยันด้วย screenshot 375px (UX review) */
@media (max-width: 575.98px) {
  .clock-btn { width: min(38vw, 138px); height: min(38vw, 138px); font-size: 1rem; box-shadow: 0 10px 24px var(--brand-shadow); }
  .clock-btn .fs-3 { font-size: 1.4rem !important; }
  .clock-btn small { font-size: .7rem; }
}
.clock-btn small { font-size: .78rem; font-weight: var(--fw-medium); opacity: .9; }

/* ---------- ESS employee hero (premium personal dashboard) ---------- */
.ess-hero { position: relative; overflow: hidden; background: linear-gradient(135deg, var(--brand-600), var(--brand-800, var(--brand-700))); color: #fff; border-radius: var(--r-lg, 18px); padding: 1.05rem 1.1rem; box-shadow: 0 12px 30px var(--brand-shadow); }
/* decorative orbs (depth, premium) — ไม่รบกวนเนื้อหา */
.ess-hero::before { content: ""; position: absolute; top: -40px; right: -30px; width: 150px; height: 150px; border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,.18), transparent 70%); pointer-events: none; }
.ess-hero::after { content: ""; position: absolute; bottom: -50px; left: -20px; width: 130px; height: 130px; border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,.10), transparent 70%); pointer-events: none; }
.ess-hero > * { position: relative; z-index: 1; }
.ess-hero-row { display: flex; align-items: center; gap: .85rem; flex-wrap: wrap; }
/* UX review: dark mode ให้ hero มีขอบชัด (เดิม gradient กลืนพื้น dark) */
[data-theme="dark"] .ess-hero { border: 1px solid var(--border); }
/* UX review: touch target ของ filter /my-requests บนมือถือ ≥44px (เดิม form-select-sm 31px กดยาก) */
@media (max-width: 575.98px) {
  #mrFilter .form-select-sm, #mrFilter .btn-sm { min-height: 44px; }
  /* ฟอร์มพนักงาน (create #empCreateForm / edit #empForm) — การ์ด identity ใช้ -sm 31px กดยากบนมือถือ */
  #empCreateForm .form-control-sm, #empCreateForm .form-select-sm,
  #empForm .form-control-sm, #empForm .form-select-sm { min-height: 44px; }
}
.ess-avatar { width: 52px; height: 52px; flex: 0 0 52px; border-radius: 50%; background: rgba(255,255,255,.20); display: flex; align-items: center; justify-content: center; font-weight: var(--fw-bold); font-size: 1.2rem; letter-spacing: .5px; }
.ess-hero-main { flex: 1 1 140px; min-width: 0; }
.ess-hello { font-size: .78rem; opacity: .85; }
.ess-name { font-size: 1.18rem; font-weight: var(--fw-bold); line-height: 1.2; overflow: hidden; text-overflow: ellipsis; }
.ess-meta { font-size: .76rem; opacity: .92; display: flex; gap: .5rem .8rem; flex-wrap: wrap; margin-top: .15rem; }
/* กัน "RET-0001" แตกที่เครื่องหมายขีดบน Safari/จอใหญ่ (iPhone Pro Max) — แต่ละ span อยู่บรรทัดเดียว ไม่ตัดกลางคำ */
.ess-meta span { white-space: nowrap; display: inline-flex; align-items: center; gap: .3rem; }
.ess-status-pill { font-size: .72rem; font-weight: var(--fw-semibold); padding: .32rem .62rem; border-radius: 999px; white-space: nowrap; align-self: center; }
.ess-status-pill.on { background: rgba(255,255,255,.24); }
.ess-status-pill.off { background: rgba(0,0,0,.20); }
.ess-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-top: .9rem; }
.ess-stat { background: rgba(255,255,255,.14); border-radius: 12px; padding: .55rem .35rem; text-align: center; color: #fff; text-decoration: none; transition: background var(--t-fast); }
.ess-stat:hover, .ess-stat:focus { background: rgba(255,255,255,.26); color: #fff; }
.ess-stat-num { font-size: 1.35rem; font-weight: var(--fw-bold); line-height: 1; }
.ess-stat-lbl { font-size: .68rem; opacity: .92; margin-top: .25rem; display: block; }
@media (max-width: 360px) { .ess-stat-lbl { font-size: .62rem; } .ess-name { font-size: 1.05rem; } }

/* ---------- ปฏิทินส่วนตัว (My Calendar) ---------- */
.cal-card { padding: 1rem; }
.cal-toolbar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.cal-month { font-size: 1.1rem; font-weight: var(--fw-bold); color: var(--text); }
.btn-icon { width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head { margin-bottom: 4px; }
.cal-dow { text-align: center; font-size: .72rem; font-weight: var(--fw-semibold); color: var(--text-3); padding: .2rem 0; }
.cal-dow.cal-weekend { color: var(--danger-text); }
.cal-cell { position: relative; aspect-ratio: 1 / 1; border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding: .3rem 0 0; background: var(--surface-2, #f8fafc); color: var(--text-2); font-size: .82rem; }
.cal-cell.cal-empty { background: transparent; }
.cal-cell.cal-has { cursor: pointer; background: var(--surface-3); transition: transform var(--t-fast), box-shadow var(--t-fast); }
.cal-cell.cal-has:hover, .cal-cell.cal-has:focus { transform: translateY(-1px); box-shadow: var(--sh-sm, 0 2px 8px rgba(0,0,0,.08)); outline: none; }
.cal-cell.cal-has:focus-visible { outline: 2px solid var(--brand-500, #6366f1); outline-offset: 1px; }
.cal-cell.cal-weekend { color: var(--danger-text); }
.cal-cell.cal-today { background: var(--brand-600, #4f46e5); color: #fff; font-weight: var(--fw-bold); }
.cal-cell.cal-today .cal-day { color: #fff; }
.cal-day { line-height: 1.1; }
.cal-dots { display: flex; gap: 2px; flex-wrap: wrap; justify-content: center; margin-top: 2px; max-width: 90%; }
.cal-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
/* สี legend ชนิด event (categorical คงที่ light/dark เหมือน avatar .aN) — แทน hardcode hex ใน view */
.cal-dot-leave{background:#6366f1}.cal-dot-ot{background:#f59e0b}.cal-dot-shift{background:#0ea5e9}.cal-dot-holiday{background:#ef4444}
.cal-pills { display: none; }
/* desktop: แสดง event pill ในเซลล์แทน dot (ใช้พื้นที่จอใหญ่ให้คุ้ม) */
@media (min-width: 768px) {
  .cal-cell { aspect-ratio: auto; min-height: 84px; align-items: stretch; padding: .3rem .35rem; }
  .cal-cell .cal-day { align-self: flex-start; }
  .cal-dots { display: none; }
  .cal-pills { display: flex; flex-direction: column; gap: 2px; margin-top: 3px; width: 100%; overflow: hidden; }
  .cal-pill { font-size: .68rem; line-height: 1.3; padding: 1px 5px; border-radius: 5px; border: 1px solid transparent; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: var(--fw-medium); }
  .cal-pill-more { font-size: .64rem; color: var(--text-3); padding-left: 4px; }
  .cal-cell.cal-today .cal-pill { filter: brightness(1.05); }
}
.cal-legend { display: flex; flex-wrap: wrap; gap: .5rem .9rem; justify-content: center; margin-top: .85rem; padding-top: .75rem; border-top: 1px solid var(--border); }
.cal-leg { font-size: .74rem; color: var(--text-3); display: inline-flex; align-items: center; gap: .3rem; }
/* agenda */
.cal-agenda { display: flex; flex-direction: column; gap: .85rem; }
.cal-ag-day { display: flex; gap: .75rem; border-radius: 12px; transition: background var(--t-fast); padding: .35rem; }
.cal-ag-flash { background: var(--brand-50, rgba(99,102,241,.12)); }
.cal-ag-date { flex: 0 0 52px; text-align: center; border-radius: 10px; background: var(--surface-3); padding: .4rem 0; align-self: flex-start; }
.cal-ag-date.is-today { background: var(--brand-600, #4f46e5); color: #fff; }
.cal-ag-dnum { display: block; font-size: 1.3rem; font-weight: var(--fw-bold); line-height: 1; }
.cal-ag-dlbl { display: block; font-size: .64rem; color: var(--text-3); margin-top: .15rem; }
.cal-ag-date.is-today .cal-ag-dlbl { color: rgba(255,255,255,.85); }
.cal-ag-evs { flex: 1 1 auto; display: flex; flex-direction: column; gap: .4rem; min-width: 0; }
.cal-ag-ev { display: flex; gap: .55rem; align-items: stretch; background: var(--surface-2, #f8fafc); border-radius: 10px; padding: .5rem .6rem; }
.cal-ev-bar { flex: 0 0 4px; border-radius: 4px; }
.cal-ev-body { display: flex; flex-direction: column; min-width: 0; }
.cal-ev-label { font-weight: var(--fw-semibold); color: var(--text); font-size: .88rem; }
.cal-ev-sub { font-size: .76rem; color: var(--text-3); }

/* ---------- Simple-mode menu toggle ---------- */
.side-mode-toggle { display: flex; align-items: center; gap: .5rem; width: 100%; background: none; border: 1px dashed var(--side-border, var(--border)); color: var(--side-text-muted, var(--text-3)); border-radius: 9px; padding: .5rem .7rem; font-size: .82rem; cursor: pointer; transition: all var(--t-fast); margin-bottom: .5rem; }
.side-mode-toggle:hover { color: var(--side-text, var(--text)); border-color: var(--brand-400, #818cf8); }
.side-mode-toggle .bi { font-size: 1rem; }

/* ---------- Onboarding tour (spotlight) ---------- */
body.tour-open { overflow: hidden; }
.tour-overlay { position: fixed; inset: 0; z-index: 3000; }
.tour-spot { position: fixed; border-radius: 12px; box-shadow: 0 0 0 9999px rgba(8,12,24,.62); border: 2px solid var(--brand-400, #818cf8); transition: all .3s cubic-bezier(.4,0,.2,1); pointer-events: none; }
.tour-pop { position: fixed; z-index: 3001; background: var(--surface); color: var(--text); border-radius: 14px; box-shadow: 0 18px 50px rgba(0,0,0,.4); padding: 1rem 1.1rem; border: 1px solid var(--border); }
.tour-pop-head { margin-bottom: .25rem; }
.tour-pop-step { font-size: .72rem; color: var(--brand-text, #4f46e5); font-weight: var(--fw-semibold); }
.tour-pop-title { font-size: 1.05rem; font-weight: var(--fw-bold); margin-bottom: .25rem; }
.tour-pop-text { font-size: .88rem; color: var(--text-2); line-height: 1.5; }
.tour-dots { display: flex; gap: 5px; justify-content: center; margin: .75rem 0 .6rem; }
.tour-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border-2); }
.tour-dot.on { background: var(--brand-600, #4f46e5); width: 18px; border-radius: 4px; }
.tour-pop-foot { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.tour-foot-right { display: flex; gap: .4rem; }
.tour-skip { color: var(--text-3); padding: .25rem .4rem; }

/* ---------- Settings hub (รวมหน้า config) ---------- */
.hub-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .5rem; }
.hub-tile { display: flex; align-items: center; gap: .55rem; padding: .65rem .8rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text-2); text-decoration: none; font-size: .88rem; transition: all var(--t-fast); }
.hub-tile:hover { border-color: var(--brand-400, #818cf8); background: var(--surface-2); color: var(--text); transform: translateY(-1px); }
.hub-tile .bi { font-size: 1.05rem; color: var(--brand-text, #4f46e5); flex: 0 0 auto; }

/* ---------- Directory (สมุดรายชื่อ) ---------- */
.dir-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .75rem; }
.dir-card { display: flex; gap: .75rem; align-items: flex-start; padding: .85rem; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; text-decoration: none; color: var(--text); transition: transform var(--t-fast), box-shadow var(--t-fast), border-color var(--t-fast); }
.dir-card:hover { transform: translateY(-2px); box-shadow: var(--sh-md); border-color: var(--brand-400, #818cf8); color: var(--text); }
.dir-avatar { width: 52px; height: 52px; flex: 0 0 52px; border-radius: 50%; object-fit: cover; }
.dir-avatar-ph { display: flex; align-items: center; justify-content: center; font-weight: var(--fw-bold); color: #fff; }
.dir-body { min-width: 0; flex: 1 1 auto; }
.dir-name { font-weight: var(--fw-semibold); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dir-nick { font-weight: var(--fw-normal); color: var(--text-3); font-size: .85em; }
.dir-pos { font-size: .82rem; color: var(--text-2); }
.dir-dept, .dir-contact { font-size: .76rem; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dir-contact { margin-top: .15rem; }
/* โทร/เมล แตะได้ (พนักงาน role 10 คลิกการ์ดดูโปรไฟล์ไม่ได้ → ใช้ติดต่อแทน) */
a.dir-contact-link { display: block; color: var(--brand-600); text-decoration: none; min-height: 28px; line-height: 28px; }
a.dir-contact-link:hover { text-decoration: underline; }

/* ---------- Engagement (Kudos) ---------- */
.ku-badges { display: flex; flex-wrap: wrap; gap: .35rem; }
.ku-badge { display: inline-flex; align-items: center; gap: .3rem; font-size: .78rem; padding: .3rem .6rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer; transition: all var(--t-fast); }
.ku-badge:hover { border-color: var(--brand-400, #818cf8); }
.ku-badge.active { background: var(--brand-600, #4f46e5); color: #fff; border-color: transparent; }
.ku-typeahead { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; margin-top: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--sh-dropdown); max-height: 240px; overflow-y: auto; padding: .25rem; }
.ku-ta-item { display: block; width: 100%; text-align: left; background: none; border: none; padding: .5rem .6rem; border-radius: 8px; color: var(--text); cursor: pointer; }
.ku-ta-item:hover, .ku-ta-item:focus { background: var(--surface-3); }
.ku-feed { display: flex; flex-direction: column; gap: .65rem; }
.ku-card { display: flex; gap: .7rem; padding: .75rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.ku-card-ico { width: 40px; height: 40px; flex: 0 0 auto; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; }
.ku-card-body { min-width: 0; flex: 1 1 auto; }
.ku-card-head { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.ku-card-msg { margin-top: .25rem; color: var(--text-2); }
.ku-card-time { margin-top: .25rem; }

/* ---------- Onboarding checklist ---------- */
.chk-list { display: flex; flex-direction: column; gap: .4rem; }
.chk-item { display: flex; align-items: center; gap: .7rem; padding: .6rem .75rem; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; transition: background var(--t-fast), border-color var(--t-fast); margin: 0; }
.chk-item:hover { background: var(--surface-2); }
.chk-box { width: 20px; height: 20px; flex: 0 0 auto; cursor: pointer; accent-color: var(--brand-600, #4f46e5); }
.chk-body { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.chk-title { font-weight: var(--fw-medium); color: var(--text); }
.chk-item.is-done { background: var(--success-soft); border-color: transparent; }
.chk-item.is-done .chk-title { text-decoration: line-through; color: var(--text-3); }
.chk-done { flex: 0 0 auto; }

/* ---------- Org Chart (visual tree) ---------- */
.org-chart-card { overflow-x: auto; }
.org-tree { min-width: max-content; padding: .5rem; }
.org-box { display: inline-flex; align-items: center; gap: .6rem; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .6rem .85rem; box-shadow: var(--sh-card); min-width: 220px; max-width: 280px; }
.org-box > .bi:first-child { font-size: 1.3rem; flex: 0 0 auto; }
.org-box-main { min-width: 0; flex: 1 1 auto; }
.org-box-name { font-weight: var(--fw-semibold); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.org-box-meta { font-size: .74rem; color: var(--text-3); }
.org-box-root { background: linear-gradient(135deg, var(--brand-600), var(--brand-800, var(--brand-700))); color: #fff; border: none; box-shadow: 0 10px 24px var(--brand-shadow); }
.org-box-root .org-box-name, .org-box-root .org-box-meta, .org-box-root > .bi { color: #fff; }
.org-box-dept { cursor: pointer; transition: transform var(--t-fast), box-shadow var(--t-fast), border-color var(--t-fast); width: 100%; }
.org-box-dept:hover, .org-box-dept:focus-visible { transform: translateY(-2px); box-shadow: var(--sh-md); border-color: var(--brand-400, #818cf8); outline: none; }
.org-box-dept .bi:first-child { color: var(--brand-text, #4f46e5); }
.org-box-arrow { margin-left: auto; color: var(--text-3); font-size: .9rem; }
/* tree connectors */
.org-root { display: inline-flex; flex-direction: column; align-items: center; }
.org-children { display: flex; gap: 1rem; margin-top: 1.6rem; position: relative; flex-wrap: wrap; justify-content: center; }
.org-children::before { content: ""; position: absolute; top: -.8rem; left: 0; right: 0; height: 2px; background: var(--border); }
.org-children > .org-node { position: relative; }
.org-children > .org-node::before { content: ""; position: absolute; top: -.8rem; left: 50%; width: 2px; height: .8rem; background: var(--border); }
.org-root > .org-box-root + .org-children::after { content: ""; position: absolute; }
.org-root::after { }
.org-root > .org-box-root { position: relative; }
.org-root > .org-box-root::after { content: ""; position: absolute; bottom: -.8rem; left: 50%; width: 2px; height: .8rem; background: var(--border); }
@media (max-width: 575.98px) {
  .org-children { flex-direction: column; gap: .6rem; margin-top: 1rem; }
  .org-children::before { display: none; }
  .org-children > .org-node::before { display: none; }
  .org-box { min-width: 0; max-width: none; width: 100%; }
}
/* employee drill-down list */
.org-emp-list { display: flex; flex-direction: column; gap: .4rem; }
.org-emp { display: flex; align-items: center; gap: .6rem; padding: .45rem .25rem; border-bottom: 1px solid var(--border); }
.org-emp:last-child { border-bottom: none; }
.org-emp-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.org-emp-name { font-weight: var(--fw-medium); color: var(--text); }
.org-emp-pos { font-size: .76rem; color: var(--text-3); }

/* ---------- Dropdowns / modals (Bootstrap polish) ---------- */
.dropdown-menu { border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--sh-dropdown); padding: .4rem; font-size: .875rem; background: var(--surface); color: var(--text); }
.dropdown-item { border-radius: var(--r-xs); padding: .5rem .7rem; color: var(--text-2); }
.dropdown-item:hover, .dropdown-item:focus { background: var(--surface-3); color: var(--text); }
/* F-12: keyboard focus distinct from hover, inset so it isn't clipped by the menu radius */
.dropdown-item:focus-visible { outline: 2px solid var(--ring-outline); outline-offset: -2px; background: var(--brand-soft); color: var(--brand-text); }
.dropdown-item.active, .dropdown-item:active { background: var(--brand-soft); color: var(--brand-text); }
.dropdown-divider { border-color: var(--border); }
/* Bootstrap .dropdown-item-text / .dropdown-header keep a default near-black color (#212529) that is invisible
   on the dark dropdown surface — bind to theme tokens (fixes notification dropdown header in dark). */
.dropdown-item-text { color: var(--text); }
.dropdown-header { color: var(--muted); }
/* Bootstrap .list-group-item ships a default #212529 color + #fff bg → invisible on dark surfaces. Theme it. */
.list-group-item { color: var(--text); background-color: transparent; border-color: var(--border); }
/* Bootstrap semantic text utilities (.text-warning #ffc107, .text-info #0dcaf0, ...) fail BOTH on white
   (light, e.g. yellow 1.6:1) and on dark — rebind to theme-adaptive --*-text tokens (≥4.5:1 in both modes). */
.text-primary { color: var(--brand-text) !important; }
.text-success { color: var(--success-text) !important; }
.text-danger  { color: var(--danger-text) !important; }
.text-warning { color: var(--warning-text) !important; }
.text-info    { color: var(--info-text) !important; }
.modal-content { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-lg); }
.modal-header { border-bottom: 1px solid var(--border); padding: 1rem 1.25rem; }
.modal-title { font-weight: var(--fw-bold); font-size: 1.05rem; }
.modal-body { padding: 1.25rem; }
.modal-footer { border-top: 1px solid var(--border); padding: .85rem 1.25rem; }
.offcanvas { background: var(--surface); color: var(--text); }
/* Inline <code>: Bootstrap default #d63384 pink fails on dark surfaces — theme to a dark-safe accent. */
code { color: var(--brand-text); }
/* Bootstrap .popover defaults to a light surface — theme it so it isn't a white box in dark mode. */
.popover { background: var(--elevated); border-color: var(--border); color: var(--text); }
.popover .popover-header { background: var(--surface-2); color: var(--text); border-bottom-color: var(--border); }
.popover .popover-body { color: var(--text-2); }
.popover .popover-arrow::after { border-top-color: var(--elevated); border-bottom-color: var(--elevated); }
/* Bootstrap tab/pill .nav-link default color fails on dark — theme (sidebar uses .nav-item, unaffected). */
.nav-link { color: var(--text-2); }
.nav-link:hover { color: var(--text); }
.nav-link.active, .nav-link[aria-selected="true"] { color: var(--brand-text); }
/* Bootstrap .accordion ships hardcoded light-blue active bg (#cfe2ff) + dark chevron → broken in dark.
   Rebind via Bootstrap's own CSS vars to theme tokens (active bg neutral so nested badges stay readable). */
.accordion {
  --bs-accordion-bg: transparent; --bs-accordion-color: var(--text); --bs-accordion-border-color: var(--border);
  --bs-accordion-active-bg: var(--surface-2); --bs-accordion-active-color: var(--brand-text);
  --bs-accordion-btn-color: var(--text); --bs-accordion-btn-bg: transparent; --bs-accordion-btn-focus-box-shadow: var(--ring);
}
.accordion-item { background: var(--surface); }
[data-theme="dark"] .accordion-button::after { filter: brightness(0) invert(.8); }

/* ---------- Toasts ---------- */
#toastZone { position: fixed; top: 1rem; right: 1rem; z-index: var(--z-toast); display: flex; flex-direction: column; gap: .6rem; max-width: 360px; }
.hr-toast { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--brand); border-radius: var(--r-md); box-shadow: var(--sh-lg); padding: .8rem 1rem; display: flex; gap: .65rem; align-items: flex-start; animation: hr-toast-in var(--t) var(--ease); }
.hr-toast.success { border-left-color: var(--success); }
.hr-toast.error { border-left-color: var(--danger); }
.hr-toast.warning { border-left-color: var(--warning); }
.hr-toast .ht-ico { font-size: 1.15rem; }
.hr-toast.success .ht-ico { color: var(--success-text); }
.hr-toast.error .ht-ico { color: var(--danger-text); }
.hr-toast.warning .ht-ico { color: var(--warning-text); }
@keyframes hr-toast-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

/* ---------- Mobile bottom nav ---------- */
.bottom-nav { display: none; }

/* ---------- Utilities ---------- */
.text-2 { color: var(--text-2) !important; }
.text-muted { color: var(--muted) !important; }
.soft-divider { height: 1px; background: var(--border); border: 0; margin: 1rem 0; }
.money { font-variant-numeric: tabular-nums; font-weight: var(--fw-semibold); }
.dim { color: var(--muted); }
.elevate { box-shadow: var(--sh-card); }
.bg-soft { background: var(--surface-2); }
.rounded-lg { border-radius: var(--r-lg) !important; }
.cursor-pointer, .clickable { cursor: pointer; }
.token-swatch { height: 44px; border-radius: var(--r-sm); box-shadow: inset 0 0 0 1px rgba(0,0,0,.05); }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--sh-lg); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .topbar { padding: 0 .9rem; }
  .topbar .menu-toggle { display: inline-grid; }
  .topbar-search { display: none; }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: calc(var(--z-side) - 1); opacity: 0; visibility: hidden; transition: opacity var(--t); }
  .sidebar-backdrop.show { opacity: 1; visibility: visible; }
}
@media (max-width: 767.98px) {
  .content { padding: 1rem .9rem 5.5rem; }
  .page-title { font-size: 1.2rem; }
  .stat-card .stat-value { font-size: 1.5rem; }
  /* Responsive table -> stacked cards. Mark <td data-label="…"> in views. */
  .table-responsive-cards thead { display: none; }
  .table-responsive-cards tbody tr { display: block; border: 1px solid var(--border); border-radius: var(--r-md); margin-bottom: .7rem; padding: .35rem .15rem; box-shadow: var(--sh-xs); background: var(--surface); }
  .table-responsive-cards tbody td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .5rem .85rem !important; border-bottom: 1px solid var(--border); text-align: right; }
  .table-responsive-cards tbody tr td:last-child { border-bottom: 0; }
  .table-responsive-cards tbody td::before { content: attr(data-label); font-weight: var(--fw-semibold); color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; text-align: left; }
  /* ตารางที่มี <tfoot> (แถวสรุปรวม) — ให้ table/tfoot เป็น block แล้วจัด tfoot เป็น card เหมือน tbody
     (ไม่งั้น <table> ค้าง layout ตาม tfoot ที่ยังเป็น table-row → card ขยายไม่เต็มจอ) */
  .table-responsive-cards { display: block; width: 100%; }
  .table-responsive-cards tbody { display: block; width: 100%; } /* ไม่งั้น tbody เป็น table-row-group → card หดตามเนื้อหา (ไม่เต็มจอ) */
  .table-responsive-cards tfoot { display: block; }
  .table-responsive-cards tfoot tr { display: block; border: 1px solid var(--border); border-radius: var(--r-md); margin-bottom: .7rem; padding: .35rem .15rem; background: var(--surface-2, var(--surface)); font-weight: var(--fw-semibold); }
  .table-responsive-cards tfoot td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .5rem .85rem !important; border-bottom: 1px solid var(--border); text-align: right; }
  .table-responsive-cards tfoot td::before { content: attr(data-label); font-weight: var(--fw-semibold); color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; text-align: left; }
  .table-responsive-cards tfoot tr td:last-child { border-bottom: 0; }
  /* แถวรายละเอียด (collapse) ใน payroll-run — ไม่ทำเป็น card + คงพฤติกรรม collapse (ซ่อนเมื่อยังไม่กาง) */
  .table-responsive-cards tbody tr.pr-collapse-row { border: 0; box-shadow: none; background: transparent; margin: 0 0 .7rem; padding: 0; }
  .table-responsive-cards tbody tr.pr-collapse-row:not(.show) { display: none; }
  .table-responsive-cards tbody tr.pr-collapse-row td.pr-detail-cell { display: block; text-align: left; padding: .25rem !important; border: 0; }
  .table-responsive-cards tbody tr.pr-collapse-row td.pr-detail-cell::before { content: none; }
  .table-responsive-cards .pr-expand-btn { min-width: 44px; min-height: 44px; } /* touch target (override global 40px) */
  .row-actions { opacity: 1; }
}
@media (max-width: 575.98px) {
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: 64px; background: var(--surface);
    border-top: 1px solid var(--border); z-index: var(--z-bottomnav); justify-content: space-around; align-items: stretch;
    padding-bottom: env(safe-area-inset-bottom, 0); box-shadow: 0 -4px 20px rgba(15,23,42,.06);
  }
  .bottom-nav a { color: var(--muted); font-size: .66rem; text-align: center; display: flex; flex-direction: column; gap: 2px; align-items: center; justify-content: center; flex: 1; font-weight: var(--fw-medium); transition: color var(--t-fast); }
  .bottom-nav a i { font-size: 1.3rem; }
  .bottom-nav a.active { color: var(--brand); }
  .bottom-nav a.active i { transform: translateY(-1px); }
  /* drawer ends above the 64px bottom-nav so the pinned footer (logout) is never covered */
  .sidebar { bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
  .fab { display: grid; }
  .page-head .ph-actions { width: 100%; }
  .page-head .ph-actions .btn { flex: 1; justify-content: center; }
  /* card-head action group (search + export + add): ให้ยืดเต็มแถว + wrap บนจอแคบ
     แทนที่จะล้นขอบการ์ด (flex-shrink-0 + search 14rem + ปุ่ม กว้างเกิน 375px).
     ครอบคลุมทุกหน้าที่ใช้ pattern "card-head d-flex flex-wrap" (28 view). */
  .card-head.flex-wrap > .d-flex:last-child { width: 100%; flex-wrap: wrap; }
  .card-head.flex-wrap > .d-flex:last-child .input-group { max-width: none !important; flex: 1 1 100%; }
  /* larger touch targets */
  .btn { min-height: 40px; }
  .icon-btn { width: 42px; height: 42px; }
}

/* print: hide app chrome (print.css handles document layout) */
@media print {
  .sidebar, .topbar, .bottom-nav, #toastZone, .fab, .ph-actions { display: none !important; }
  .main { margin-left: 0 !important; }
  .content { padding: 0 !important; max-width: none; }
}

/* =====================================================================
   Premium polish — entrance motion, micro-interactions, a11y, fine-tuning
   ===================================================================== */

/* tabular numbers so KPI/money columns align perfectly */
.stat-value, .money, .table td.text-end, .ring-stat .ring-in { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* subtle entrance: page header + cards fade-up on load (disabled for reduced-motion via theme.css) */
@keyframes hr-fade-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.content > .page-head,
.content > .row,
.content > .card,
.content > .table-card-wrap,
.content > .filter-bar { animation: hr-fade-up .42s var(--ease) both; }
.content > .row:nth-of-type(2) { animation-delay: .04s; }
.content > .row:nth-of-type(3) { animation-delay: .08s; }
.content > .card, .content > .table-card-wrap { animation-delay: .06s; }
/* stagger KPI tiles within the first row for a refined cascade */
.content > .row:first-of-type > [class*="col-"]:nth-child(1) .stat-card { animation: hr-fade-up .4s var(--ease) both; animation-delay: .02s; }
.content > .row:first-of-type > [class*="col-"]:nth-child(2) .stat-card { animation: hr-fade-up .4s var(--ease) both; animation-delay: .06s; }
.content > .row:first-of-type > [class*="col-"]:nth-child(3) .stat-card { animation: hr-fade-up .4s var(--ease) both; animation-delay: .10s; }
.content > .row:first-of-type > [class*="col-"]:nth-child(4) .stat-card { animation: hr-fade-up .4s var(--ease) both; animation-delay: .14s; }
.content > .row:first-of-type > [class*="col-"]:nth-child(5) .stat-card { animation: hr-fade-up .4s var(--ease) both; animation-delay: .18s; }
.content > .row:first-of-type > [class*="col-"]:nth-child(6) .stat-card { animation: hr-fade-up .4s var(--ease) both; animation-delay: .22s; }

/* refined interactions */
.nav-item, .qa-card, .list-row, .stat-card, .icon-btn, .btn, .badge-soft, .dropdown-item { transition: all var(--t-fast) var(--ease); }
.list-row { border-radius: var(--r-sm); padding-inline: .5rem; }
.list-row:hover { background: var(--surface-2); }
tr { transition: background var(--t-fast); }
.table > tbody > tr:hover td:first-child { box-shadow: inset 3px 0 0 var(--brand-400); }
.card-hover:active, .qa-card:active, .stat-card:active { transform: translateY(0); }
.icon-btn:active { transform: scale(.92); }
.avatar { transition: transform var(--t-fast); }
.media-row:hover .avatar { transform: scale(1.06); }

/* chart container: skeleton shimmer ONLY until JS adds .ready (dashboard.js) */
.chart-wrap:not(.ready)::before {
  content: ""; position: absolute; inset: 0; border-radius: var(--r-md);
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--border) 37%, var(--surface-3) 63%);
  background-size: 400% 100%; animation: hr-shimmer 1.3s ease infinite; opacity: .5; z-index: 0;
}
.chart-wrap canvas, .chart-wrap .state { position: relative; z-index: 1; }

/* premium focus ring + keyboard skip link (accessibility) */
.skip-link {
  position: fixed; top: -60px; left: 12px; z-index: 2000; background: var(--brand); color: #fff;
  padding: .55rem 1rem; border-radius: var(--r-sm); font-weight: var(--fw-semibold); box-shadow: var(--sh-lg);
  transition: top var(--t) var(--ease);
}
.skip-link:focus { top: 12px; color: #fff; }
a:focus-visible, button:focus-visible, .nav-item:focus-visible, .form-control:focus-visible { outline: 2px solid var(--ring-outline); outline-offset: 2px; box-shadow: var(--ring); }

/* tidy: consistent card title icon color + crisper dividers + nicer disabled */
.card-title i, .page-title i { opacity: .95; }
.table > thead th { position: relative; }
:disabled, .disabled { cursor: not-allowed; opacity: .6; }
.btn:disabled { box-shadow: none; transform: none; }

/* number emphasis in stat cards */
.stat-card .stat-value { background: linear-gradient(180deg, var(--text), color-mix(in srgb, var(--text) 80%, var(--muted))); -webkit-background-clip: text; background-clip: text; }
@supports not (background-clip: text) { .stat-card .stat-value { background: none; color: var(--text); } }

/* impersonation banner */
.impersonate-banner {
  display: flex; align-items: center; gap: .6rem; padding: .55rem 1.25rem;
  background: linear-gradient(90deg, #fff7ed, #fffbeb); border-bottom: 2px solid var(--warning);
  color: #92400e; font-size: .85rem; font-weight: var(--fw-semibold); position: sticky; top: 0; z-index: calc(var(--z-top) + 2);
}
.impersonate-banner i { font-size: 1.05rem; }
[data-theme="dark"] .impersonate-banner { background: rgba(217,119,6,.16); color: #fbbf24; border-bottom-color: var(--warning); }

/* ── Top progress bar (pjax navigation) ───────────────────────── */
#hrProgress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 4000; pointer-events: none; background: transparent; }
#hrProgressBar { height: 100%; width: 0; opacity: 0; border-radius: 0 3px 3px 0;
  background: linear-gradient(90deg, var(--brand-600,#4f46e5), var(--brand-400,#818cf8) 70%, var(--info-text,#38bdf8));
  box-shadow: 0 0 10px var(--brand-500,#6366f1), 0 0 4px var(--brand-400,#818cf8);
  transition: width .2s ease, opacity .35s ease; }
#hrProgress.active #hrProgressBar { opacity: 1; }
/* subtle content fade-in after pjax swap */
#mainContent.pjax-in { animation: pjaxFade .28s ease; }
@keyframes pjaxFade { from { opacity: .35; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce){ #mainContent.pjax-in{ animation: none; } }

/* ── Command Palette (Cmd+K / global search) ─────────────────── */
.cmdk { position: fixed; inset: 0; z-index: 5000; display: flex; align-items: flex-start; justify-content: center; }
.cmdk[hidden] { display: none; }
.cmdk-backdrop { position: absolute; inset: 0; background: rgba(8,14,28,.55); backdrop-filter: blur(3px); }
.cmdk-panel { position: relative; width: min(640px, 92vw); margin-top: 12vh; background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 24px 64px rgba(8,14,28,.45); overflow: hidden; animation: cmdkIn .18s ease; }
@keyframes cmdkIn { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: none; } }
.cmdk-input-row { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.cmdk-input-row i { color: var(--text-2); font-size: 1.1rem; }
.cmdk-input-row input { flex: 1; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 1.05rem; }
.cmdk-results { max-height: 52vh; overflow-y: auto; padding: 6px; }
.cmdk-group-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); padding: 8px 10px 4px; }
.cmdk-item { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 10px; cursor: pointer; color: var(--text); }
.cmdk-item .ci-ico { width: 30px; height: 30px; flex: 0 0 auto; display: flex; align-items: center; justify-content: center; border-radius: 8px; background: var(--surface-2); color: var(--brand-text,#4f46e5); }
.cmdk-item .ci-main { flex: 1; min-width: 0; }
.cmdk-item .ci-label { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmdk-item .ci-sub { font-size: .78rem; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmdk-item.active, .cmdk-item:hover { background: var(--brand-soft, #eef2ff); }
.cmdk-item.active .ci-ico { background: var(--brand-600,#4f46e5); color: #fff; }
.cmdk-empty { text-align: center; color: var(--text-2); padding: 28px; }
.cmdk-footer { display: flex; gap: 16px; padding: 8px 14px; border-top: 1px solid var(--border); font-size: .74rem; color: var(--text-2); }
.cmdk-footer kbd { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; margin-right: 3px; }

/* ── Skeleton loader (pjax slow page) ─────────────────────────── */
.skel { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3,#e9edf4) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: skelShimmer 1.3s ease infinite; border-radius: 8px; }
@keyframes skelShimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.skel-line { height: 12px; margin: 8px 0; }
.skel-page .skel-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md,14px); padding: 18px; margin-bottom: 16px; }
@media (prefers-reduced-motion: reduce){ .skel{ animation: none; } }

/* ── Card tabs (employee detail) ──────────────────────────────── */
.card-tabs { border-bottom: 1px solid var(--border); margin-bottom: 0; padding-bottom: 6px; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
.card-tabs::-webkit-scrollbar { height: 4px; }
.card-tabs::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.card-tabs .nav-link { color: var(--text-muted, #64748b); font-weight: 600; font-size: .9rem; padding: .5rem .85rem; border-radius: 9px; white-space: nowrap; transition: background .15s, color .15s; }
.card-tabs .nav-link.active { background: var(--brand-soft, #eef2ff); color: var(--brand-600, #4f46e5); }
.card-tabs .nav-link:not(.active):hover { background: var(--surface-2, #f1f5f9); color: var(--text); }
.card .tab-content > .tab-pane { padding: 1.1rem 1.25rem 1.25rem; }
.card .tab-content .state { padding: 28px 16px; }
/* card-head ที่มีแท็บ: เว้นช่องให้แท็บไม่ชิดขอบบน/ข้าง */
.card-head.pb-0 { padding-bottom: 0; }
.card .card-tabs { padding-left: .25rem; padding-right: .25rem; }
/* a11y: touch target ≥ 44px บนมือถือ (แท็บ + ปุ่ม action) */
@media (max-width: 575.98px) {
    .card-tabs .nav-link { min-height: 44px; display: inline-flex; align-items: center; }
    .ph-actions .btn, .ph-actions .btn-light, .ph-actions .btn-primary { min-height: 44px; }
    /* ขยาย touch target ปุ่มในการ์ด/ฟอร์ม/ตาราง ให้กดง่ายบนมือถือ */
    .card .btn:not(.btn-icon), .modal .btn:not(.btn-icon) { min-height: 40px; }
    .btn-icon { width: 40px; height: 40px; }
    .btn-icon.btn-sm { width: 36px; height: 36px; }
}

/* ── Sidebar menu badges (pending counts) ─────────────────────── */
.nav-item { position: relative; }
.nav-badge {
    margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
    background: var(--danger, #ef4444); color: #fff; font-size: .72rem; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center; line-height: 1; flex: 0 0 auto;
}
.nav-section-right { display: inline-flex; align-items: center; gap: 8px; }
.nav-grp-badge {
    min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
    background: var(--brand-600, #4f46e5); color: #fff; font-size: .68rem; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center; line-height: 1;
}
/* เมื่อ group ปิดอยู่ ให้ badge รวมยังเห็น (เด่นด้วยสีแบรนด์) */
[data-theme="dark"] .nav-badge, .dark .nav-badge { background: #f87171; color: #1a1a1a; }

/* ── Employee readiness cards (detail overview) ───────────────── */
.readiness-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.readiness-grid .rd-card, .rd-card { background: var(--surface-2, #f8fafc); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
@media (max-width: 768px) { .readiness-grid { grid-template-columns: 1fr; } }
/* directory card แบบไม่คลิก (พนักงานทั่วไปไม่มีสิทธิ์ดูโปรไฟล์) — หน้าตาเหมือนการ์ดแต่ไม่ชวนคลิก */
.dir-card-static { cursor: default; }
.dir-card-static:hover { transform: none; box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,.04)); }

/* ── Company logo (org-manage modal + table) ──────────────────── */
.co-logo-row { display: flex; gap: 1rem; align-items: flex-start; padding: 1rem; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface-2, #f8fafc); }
.co-logo-thumb {
  width: 76px; height: 76px; flex: 0 0 auto; border-radius: var(--r-md); border: 1px solid var(--border);
  background: var(--surface); display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: 1.6rem;
}
.co-logo-thumb.has-img { border-style: solid; }
.co-logo-thumb img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }
.co-cell { display: inline-flex; align-items: center; gap: .6rem; }
.co-logo-sm {
  width: 34px; height: 34px; flex: 0 0 auto; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); object-fit: contain; padding: 2px;
}
.co-logo-ph { display: inline-grid; place-items: center; color: var(--muted); font-size: .95rem; }

/* ── Branding (white-label settings) ──────────────────────────── */
.brand-asset-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
@media (max-width: 575.98px) { .brand-asset-grid { grid-template-columns: 1fr; } }
.brand-asset {
  border: 1px solid var(--border); border-radius: var(--r-lg); padding: 1rem; background: var(--surface-2, #f8fafc);
  display: flex; gap: .9rem; align-items: flex-start;
}
.brand-asset .ba-thumb {
  width: 64px; height: 64px; flex: 0 0 auto; border-radius: var(--r-md); border: 1px solid var(--border);
  background: var(--surface); display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: 1.4rem;
}
.brand-asset .ba-thumb.favicon { width: 40px; height: 40px; }
.brand-asset .ba-thumb img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }

/* ── Company form (full-page create/edit) ─────────────────────── */
/* sticky save/cancel header — ปุ่มบันทึกติดตามตลอดเวลา scroll ฟอร์มยาว */
.company-form-head {
  position: sticky; top: var(--top-h, 56px); z-index: 6;
  background: var(--bg, var(--surface)); margin-bottom: 1rem;
  padding-top: .75rem; padding-bottom: .75rem; border-bottom: 1px solid var(--border);
}
/* asset cards: contrast ชัดทั้ง light/dark (ใช้ token ไม่ hardcode) */
.co-asset { background: var(--surface-3, var(--surface-2)); border-color: var(--border-2, var(--border)); }
.co-asset .ba-thumb { background: var(--surface); border-color: var(--border-2, var(--border)); }
.co-asset .co-asset-btn, .co-asset .co-asset-remove { min-height: 38px; }
.co-asset-hint { font-size: .74rem; line-height: 1.35; }
/* soft info alert — กล่อง hint "บันทึกก่อนเพื่อปลดล็อกอัปโหลด" */
.alert-soft-info {
  background: var(--info-soft, var(--brand-soft)); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-md);
}
/* adaptive soft warning alert (token-based — แทน .alert-warning ที่ hardcode เหลือง ไม่รองรับ dark) */
.alert-soft-warning {
  background: var(--warning-soft); color: var(--warning-text);
  border: 1px solid var(--warning-border, var(--border)); border-radius: var(--r-md);
}

/* Command Center KPI band — ใช้ stat token เดียวกับทั้งระบบ (sync hierarchy กับ /dashboard,/analytics) */
.cc-kpi { transition: transform var(--t-fast), box-shadow var(--t-fast), border-color var(--t-fast); }
.cc-kpi:hover { transform: translateY(-2px); box-shadow: var(--sh-md); border-color: var(--border-2); }
.cc-kpi .stat-value { font-size: 1.45rem; font-weight: var(--fw-black); line-height: 1; letter-spacing: -1px; color: var(--text); font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.cc-kpi .stat-label { color: var(--text-2); font-size: .76rem; font-weight: var(--fw-medium); }
.cc-kpi .stat-icon { width: 38px; height: 38px; border-radius: var(--r-md); font-size: 1.05rem; }
@media (max-width: 575.98px) {
  .cc-kpi .stat-value { font-size: 1.25rem; }
  /* a11y: touch target ≥44px บนมือถือ สำหรับรายการคลิกได้ใน command center */
  #risk-center .list-group-item-action,
  .cc-action-list .list-group-item-action { min-height: 44px; }
}
@media (max-width: 991.98px) {
  /* มือถือ/แท็บเล็ต: ให้แท็บฟอร์ม (ขวา) ขึ้นก่อน asset (ซ้าย) เพื่อกรอกข้อมูลก่อน */
  .company-form-grid .company-form-aside { order: 2; }
  .company-form-grid .company-form-main { order: 1; }
  .co-asset .co-asset-btn, .co-asset .co-asset-remove { min-height: 44px; }
}
/* live preview: mock sidebar + button using the picked brand color */
.brand-preview-box {
  border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; display: flex; min-height: 150px;
}
.brand-preview-side {
  width: 150px; flex: 0 0 auto; background: var(--side-grad); color: #fff; padding: .9rem .8rem; display: flex; flex-direction: column; gap: .55rem;
}
.brand-preview-brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; font-size: .95rem; }
.brand-preview-brand .bpmark {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; color: #fff; font-size: .9rem;
  background: var(--bp-color, var(--brand-grad)); overflow: hidden;
}
.brand-preview-brand .bpmark img { width: 100%; height: 100%; object-fit: contain; }
.brand-preview-item { font-size: .78rem; padding: .35rem .5rem; border-radius: 8px; color: rgba(255,255,255,.85); display: flex; align-items: center; gap: .45rem; }
.brand-preview-item.active { background: var(--bp-color, #4f46e5); color: var(--bp-text, #fff); }
.brand-preview-main { flex: 1 1 auto; padding: 1rem; background: var(--surface); display: flex; flex-direction: column; gap: .6rem; }
.brand-preview-main .bp-btn { background: var(--bp-color, #4f46e5); color: var(--bp-text, #fff); border: 0; border-radius: var(--r-md); padding: .4rem .9rem; font-size: .82rem; font-weight: 600; align-self: flex-start; }
.brand-preview-main .bp-chip { background: var(--bp-color, #4f46e5); color: var(--bp-text, #fff); border-radius: 999px; padding: .15rem .6rem; font-size: .72rem; align-self: flex-start; }
@media (max-width: 575.98px) { .brand-preview-side { width: 120px; } }

/* ===== /design Brand Theme picker (white-label, 2026-06-24) ===== */
.theme-tpl-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; }
@media (min-width: 576px) { .theme-tpl-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.theme-tpl {
  display: flex; align-items: center; gap: .55rem; text-align: left; width: 100%;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--r-md);
  padding: .55rem .65rem; cursor: pointer; position: relative; transition: border-color .15s, box-shadow .15s, background .15s;
}
.theme-tpl:hover:not(:disabled) { border-color: var(--border-2); background: var(--surface-2); }
.theme-tpl:disabled { opacity: .6; cursor: not-allowed; }
.theme-tpl.is-active { border-color: var(--hr-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--hr-primary) 16%, transparent); }
.theme-tpl-sw { width: 26px; height: 26px; border-radius: 7px; flex: 0 0 auto; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); display: grid; place-items: center; color: #fff; font-size: .8rem; }
.theme-tpl-name { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text); line-height: 1.25; }
.theme-tpl-check { margin-left: auto; color: var(--hr-primary); opacity: 0; font-size: 1rem; transition: opacity .15s; }
.theme-tpl.is-active .theme-tpl-check { opacity: 1; }
.theme-tpl-custom .theme-tpl-sw { background: var(--brand-grad); }

.theme-nav-group, .theme-pv-group { flex-wrap: wrap; }
.theme-nav-group .btn.active, .theme-pv-group .btn.active {
  background: var(--hr-primary); color: #fff; border-color: var(--hr-primary);
}

/* live preview box — mock sidebar + content; honors its own data-brand/data-nav-style */
.theme-preview {
  border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; display: flex; min-height: 190px; background: var(--surface);
}
.theme-preview .tp-side {
  width: 150px; flex: 0 0 auto; background: var(--side-grad); color: #fff; padding: .85rem .7rem; display: flex; flex-direction: column; gap: .35rem;
}
.theme-preview .tp-brand { display: flex; align-items: center; gap: .45rem; font-weight: 800; font-size: .9rem; margin-bottom: .35rem; }
.theme-preview .tp-mark { width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; background: var(--brand-grad); color: #fff; font-size: .85rem; }
.theme-preview .tp-item {
  font-size: .76rem; padding: .35rem .5rem; border-radius: 8px; color: rgba(255,255,255,.82);
  display: flex; align-items: center; gap: .45rem; position: relative;
}
.theme-preview .tp-item.active { background: color-mix(in srgb, var(--hr-primary) 16%, transparent); color: #fff; font-weight: 700; }
.theme-preview .tp-item.active::before {
  content: ""; position: absolute; left: -.7rem; top: 18%; bottom: 18%; width: 3px; border-radius: 0 3px 3px 0; background: var(--hr-primary);
}
.theme-preview[data-nav-style="pill"] .tp-item { border-radius: 999px; }
.theme-preview[data-nav-style="pill"] .tp-item.active { background: var(--hr-primary); }
.theme-preview[data-nav-style="pill"] .tp-item.active::before { display: none; }
.theme-preview[data-nav-style="soft"] .tp-item.active { background: color-mix(in srgb, var(--hr-primary) 20%, transparent); border-radius: 10px; }
.theme-preview[data-nav-style="soft"] .tp-item.active::before { display: none; }
.theme-preview .tp-main { flex: 1 1 auto; padding: 1rem; background: var(--surface); display: flex; flex-direction: column; gap: .6rem; align-items: flex-start; }
.theme-preview .tp-chip { background: color-mix(in srgb, var(--hr-primary) 14%, transparent); color: var(--brand-text); border-radius: 999px; padding: .15rem .6rem; font-size: .72rem; }
.theme-preview .tp-btn { background: var(--hr-primary); color: #fff; border: 0; border-radius: var(--r-md); padding: .4rem .9rem; font-size: .82rem; font-weight: 600; }
.theme-preview .tp-help { display: flex; align-items: center; gap: .4rem; font-size: .76rem; color: var(--muted); margin-top: auto; }
.theme-preview .tp-q { width: 22px; height: 22px; border-radius: 999px; background: var(--hr-primary); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: .8rem; }
/* preview box dark mode follows the page's data-theme during preview */
[data-theme="dark"] .theme-preview .tp-main { background: var(--surface); }
@media (max-width: 575.98px) { .theme-preview .tp-side { width: 120px; } }

/* ===== payroll-run/show: action groups + bank badge + modal polish (design 2026-06-22) ===== */
.pr-actions-group { display: flex; flex-direction: column; gap: .5rem; }
.pr-group-label { font-size: .72rem; font-weight: var(--fw-semibold); color: var(--muted); text-transform: uppercase; letter-spacing: .4px; display: inline-flex; align-items: center; gap: .35rem; }
.pr-divider { margin: .9rem 0; border: 0; border-top: 1px solid var(--border); opacity: 1; }
.pr-bank-badge { background: var(--surface-2); color: var(--text); }
/* btn-close: SVG ดำ default มองไม่เห็นบน dark surface → invert + เพิ่ม opacity */
.btn-close { opacity: .65; }
.btn-close:hover { opacity: 1; }
[data-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(1.6); }
/* ตารางพรีวิวใน modal ให้กลมกลืน token ทั้ง light/dark */
.modal-body .table-bordered { --bs-table-bg: transparent; border-color: var(--border); }
.modal-body .table-bordered > :not(caption) > * > * { border-color: var(--border); }
.modal-body .table thead th,
.modal-body .table tr:first-child th { background: var(--surface-2); color: var(--text); }
@media (max-width: 575.98px) {
    .pr-actions-group .ms-auto { margin-left: 0 !important; }
    .pr-actions-group .d-flex > .btn,
    .pr-actions-group .btn-group { flex: 1 1 auto; }
    .pr-actions-group .btn-sm { min-height: 38px; }
}

/* ===== SPEC A — responsive header (≤640px) + Preferences ===== */
.show-mobile { display: none; }
@media (max-width: 640px) {
    .topbar .hide-mobile { display: none !important; }
    .show-mobile { display: block !important; }
    /* topbar เหลือ ~3 ปุ่ม → ไม่ wrap/overflow; เผื่อ wrap กันเหนียว */
    .topbar { flex-wrap: nowrap; gap: .25rem; }
    .topbar .icon-btn, .topbar .btn { min-width: 0; }
    /* Create → FAB ลอยมุมขวาล่าง (เหนือ bottom-nav) */
    .topbar .header-create { position: fixed; right: 1rem; bottom: 4.6rem; z-index: 1030; margin: 0; }
    .topbar .header-create > #quickAddBtn { width: 3.25rem; height: 3.25rem; border-radius: 50%; padding: 0; box-shadow: 0 8px 24px rgba(0,0,0,.22); display: inline-flex; align-items: center; justify-content: center; }
    .topbar .header-create > #quickAddBtn .bi-plus-lg { font-size: 1.35rem; }
}
/* RH-01: ช่วง 576–640px ยังไม่มี bottom-nav (โผล่ ≤575.98px) → FAB ไม่ต้องยกสูงเผื่อ nav */
@media (min-width: 576px) and (max-width: 640px) {
    .topbar .header-create { bottom: 1.25rem; }
}

/* ===== Icon vertical alignment — audit-confirmed (root causes) =====
   Bootstrap Icons (CDN) ตั้ง .bi{vertical-align:-.125em} → ดันไอคอน inline ต่ำกว่ากลาง x-height
   ของ Noto Sans Thai บน desktop (อาการ "ไอคอนไม่อยู่ตรงกลาง/ติ๊กถูกลอยบน"). flex/grid/inline-flex
   ละเว้น vertical-align อยู่แล้ว จึงไม่กระทบปุ่ม/ชิปที่เป็น flex. */
.bi { vertical-align: -0.075em; }
/* Bootstrap .badge (ไม่ใช่ .badge-soft โปรเจกต์) + ชิปที่โดน utility .d-inline-block (!important) ทับ flex → คืน inline-flex center */
.badge { display: inline-flex; align-items: center; vertical-align: middle; }
.badge-soft.d-inline-block, .chip.d-inline-block { display: inline-flex !important; align-items: center; }
.ess-status-pill { display: inline-flex; align-items: center; gap: .35rem; }
/* ไอคอนในตาราง/alert ให้อยู่กลางบรรทัดข้อความ */
.table > tbody td .bi, .table > tbody td .bi::before { vertical-align: middle; }
.alert > .bi:first-child { vertical-align: -0.05em; }
/* .state .state-ico = icon chip อีกตัว (บั๊กแบบเดียวกับ .stat-icon) → center glyph */
.state .state-ico { display: grid; place-items: center; }
.state .state-ico > i, .state .state-ico > .bi { display: block; line-height: 1; font-size: inherit; }

/* =====================================================================
   Approvals Center (/approvals) — compact scannable row list + sticky bulk bar
   ทั้งหมดใช้ design tokens เท่านั้น (รองรับ dark/light อัตโนมัติ)
   ===================================================================== */
/* --- แท็บ pills: active เด่น, count badge ชัด, แท็บที่ 0 จาง --- */
.wf-tabs { gap: .35rem; padding-bottom: .3rem; }
.wf-tabs .nav-link {
  display: inline-flex; align-items: center; gap: .45rem; white-space: nowrap;
  color: var(--text-2); font-weight: var(--fw-semibold); font-size: .86rem;
  padding: .5rem .85rem; border-radius: var(--r-pill);
  border: 1px solid var(--border); background: var(--surface);
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.wf-tabs .nav-link:hover { background: var(--surface-3); color: var(--text); border-color: var(--border-2); }
.wf-tabs .nav-link.active {
  background: var(--brand-600); color: #fff; border-color: var(--brand-600);
  box-shadow: var(--sh-sm, 0 2px 6px rgba(0,0,0,.12));
}
.wf-tabs .nav-link .wf-count {
  min-width: 1.35rem; height: 1.35rem; padding: 0 .4rem; border-radius: var(--r-pill);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: var(--fw-bold); line-height: 1;
  background: var(--surface-3); color: var(--text-2);
}
.wf-tabs .nav-link.active .wf-count { background: rgba(255,255,255,.22); color: #fff; }
/* แท็บที่ไม่มีคำขอ (count=0) → จางลงแต่ยังกดได้ */
.wf-tabs .nav-link.is-empty:not(.active) { opacity: .55; }
.wf-tabs .nav-link.is-empty:not(.active) .wf-count { opacity: .8; }

/* --- แถวคำขอ (1 คำขอ = 1 แถว scan ได้เร็ว) --- */
.wf-list { display: flex; flex-direction: column; gap: .5rem; }
.wf-row {
  display: flex; align-items: center; gap: .75rem;
  padding: .7rem .85rem; border: 1px solid var(--border); border-radius: var(--r-md, 12px);
  background: var(--surface); transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.wf-row:hover { border-color: var(--border-2); box-shadow: var(--sh-card); }
.wf-row.is-selected { border-color: var(--brand-600); background: var(--brand-soft); }
.wf-row .wf-check { flex: 0 0 auto; width: 1.15rem; height: 1.15rem; margin: 0; cursor: pointer; }
.wf-row .avatar { flex: 0 0 auto; }
/* ตัวตน: ชื่อ + รหัส */
.wf-id { flex: 0 0 auto; min-width: 0; max-width: 200px; }
.wf-id .wf-name { font-weight: var(--fw-semibold); color: var(--text); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wf-id .wf-code { font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* เนื้อหาคำขอ — ป้ายชนิด + meta inline scan ได้เร็ว */
.wf-main { flex: 1 1 auto; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .55rem; }
.wf-main .wf-amt { font-weight: var(--fw-bold); color: var(--text); white-space: nowrap; }
.wf-main .wf-meta { font-size: .8rem; color: var(--text-2); display: inline-flex; align-items: center; gap: .3rem; white-space: nowrap; }
.wf-main .wf-meta .bi { color: var(--muted); }
.wf-main .wf-reason {
  font-size: .8rem; color: var(--muted); min-width: 0; flex: 1 1 140px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.wf-main .wf-arrow { color: var(--muted); }
.wf-main .wf-new { font-weight: var(--fw-semibold); color: var(--brand-text); }
/* ป้ายอายุ + ปุ่ม action ชิดขวา */
.wf-tail { flex: 0 0 auto; display: flex; align-items: center; gap: .4rem; margin-left: auto; }
.wf-acts { display: inline-flex; gap: .35rem; }
.wf-acts .wf-ib {
  width: 34px; height: 34px; padding: 0; border-radius: var(--r-sm);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1rem; border: 1px solid transparent; cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.wf-acts .wf-ib.js-approve { background: var(--success-soft); color: var(--success-text); }
.wf-acts .wf-ib.js-approve:hover { background: var(--success); color: var(--btn-on-bright, #fff); }
.wf-acts .wf-ib.js-reject { background: var(--danger-soft); color: var(--danger-text); }
.wf-acts .wf-ib.js-reject:hover { background: var(--danger); color: #fff; }
.wf-acts .wf-ib:focus-visible { outline: 2px solid var(--ring-outline, var(--brand-600)); outline-offset: 2px; }

/* --- แถบ bulk action ลอย (sticky) --- */
.wf-bulkbar {
  position: sticky; top: .5rem; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .6rem;
  padding: .55rem .85rem; margin-bottom: .75rem;
  background: var(--brand-600); color: #fff;
  border: 1px solid var(--brand-600); border-radius: var(--r-md, 12px);
  box-shadow: var(--sh-md, 0 8px 24px rgba(0,0,0,.18));
}
.wf-bulkbar .wf-bb-info { display: inline-flex; align-items: center; gap: .5rem; font-weight: var(--fw-semibold); }
.wf-bulkbar .wf-bb-info .wf-bb-count {
  min-width: 1.5rem; height: 1.5rem; padding: 0 .45rem; border-radius: var(--r-pill);
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.22); font-weight: var(--fw-bold); font-size: .82rem;
}
.wf-bulkbar .btn { font-weight: var(--fw-semibold); }
.wf-bulkbar .btn-on-bar { background: #fff; color: var(--brand-600); border-color: #fff; }
.wf-bulkbar .btn-on-bar:hover { background: rgba(255,255,255,.88); color: var(--brand-700, var(--brand-600)); }
.wf-bulkbar .btn-on-bar-ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.5); }
.wf-bulkbar .btn-on-bar-ghost:hover { background: rgba(255,255,255,.16); color: #fff; }

/* --- แถบหัวแต่ละแท็บ: เลือกทั้งหมด + อนุมัติทั้งหมด --- */
.wf-toolbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
  margin-bottom: .65rem;
}
.wf-toolbar .wf-selall { display: inline-flex; align-items: center; gap: .45rem; font-size: .82rem; color: var(--text-2); cursor: pointer; user-select: none; }
.wf-toolbar .wf-selall input { width: 1.05rem; height: 1.05rem; margin: 0; cursor: pointer; }

/* --- empty-state เพิ่ม sub --- */
.wf-empty .state-sub { font-size: .82rem; color: var(--muted); }

/* --- แถบกรอง (server-side: บริษัท/สาขา/ค้นหา) — สเกล 1000+ หลายบริษัท --- */
.wf-filterbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.wf-filterbar .wf-fb-search { position: relative; flex: 1 1 280px; min-width: 0; max-width: 360px; }
.wf-filterbar .wf-fb-search .wf-fb-icon {
  position: absolute; left: .7rem; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none; display: inline-flex;
}
.wf-filterbar .wf-fb-search .form-control { padding-left: 2.1rem; }
.wf-filterbar .wf-fb-sel { flex: 0 0 auto; width: auto; min-width: 160px; max-width: 220px; }

/* --- ปุ่มโหลดเพิ่ม (load-more) ท้าย list ของแต่ละแท็บ --- */
.wf-more-wrap { display: flex; justify-content: center; margin-top: .85rem; }
.wf-more { font-weight: var(--fw-semibold); min-width: 200px; }

/* --- responsive: มือถือ = แถวซ้อนอ่านง่าย + filter stack เต็มกว้าง --- */
@media (max-width: 575.98px) {
  .wf-row { flex-wrap: wrap; align-items: flex-start; row-gap: .5rem; }
  .wf-id { max-width: none; flex: 1 1 auto; }
  .wf-main { flex: 1 1 100%; order: 3; padding-left: calc(1.15rem + .75rem); }
  .wf-tail { order: 2; margin-left: auto; align-items: flex-start; }
  .wf-acts .wf-ib { width: 44px; height: 44px; } /* touch target ≥ 44px (HR กดอนุมัติบนมือถือบ่อย) */
  .wf-acts { gap: .5rem; } /* เพิ่มระยะ approve/reject กันกดผิด */
  .wf-check { width: 1.5rem; height: 1.5rem; } /* checkbox เลือกแถว ≥ touch */
  .wf-tabs .nav-link { min-height: 44px; }
  /* bulk-bar ลอยเหนือ bottom-nav (เดิม sticky-top โดน bottom-nav บัง/อยู่กลางจอ) — ถึงนิ้วโป้งง่าย ไม่หาย */
  .wf-bulkbar { position: fixed; left: .5rem; right: .5rem; top: auto; bottom: calc(64px + env(safe-area-inset-bottom, 0px) + .5rem); margin: 0; flex-direction: column; align-items: stretch; }
  .wf-bulkbar .wf-bb-btns { display: flex; gap: .4rem; }
  .wf-bulkbar .wf-bb-btns .btn { flex: 1 1 auto; }
  .wf-filterbar { flex-direction: column; align-items: stretch; }
  .wf-filterbar .wf-fb-search { flex: 1 1 auto; max-width: none; }
  .wf-filterbar .wf-fb-sel { width: 100%; max-width: none; min-height: 44px; }
  .wf-more { width: 100%; min-width: 0; }
  .wf-more-wrap { display: block; }
}
@media (min-width: 576px) and (max-width: 767.98px) {
  .wf-id { max-width: 150px; }
  .wf-acts .wf-ib { width: 44px; height: 44px; }
}
/* org-manage: touch target บนมือถือ (checkbox/ปุ่ม edit-delete เดิมเล็กกว่า 44px) */
@media (max-width: 767.98px) {
  .org-check, .org-selall { width: 1.4rem; height: 1.4rem; }
  .row-actions .btn-icon { min-width: 44px; min-height: 44px; }
}

/* =====================================================================
   C) SIDEBAR THEMING (light default + dark + nav-style bar|pill|soft)
   Brand-aware via --hr-primary; overrides legacy navy-only sidebar rules.
   Layout props (width/position/scroll) remain on .sidebar above.
   ===================================================================== */
.sidebar { background: linear-gradient(180deg,#fff 0%,#f7f9fc 100%) !important; border-right:1px solid #e7ebf2 !important; box-shadow:4px 0 24px -18px rgba(16,24,40,.25) !important; }
.sidebar .nav-section { color:#8a93a3 !important; letter-spacing:.06em; }
.sidebar a.nav-item { color:#2c333f !important; font-weight:500; }
.sidebar a.nav-item i { color:#8a93a3 !important; }
.sidebar .brand { color:#1f2937 !important; }
.sidebar .brand small { color:var(--hr-primary) !important; }
.side-foot { background:#f2f5f9 !important; border-top:1px solid #e7ebf2 !important; }
.side-foot, .side-foot * { color:#2c333f !important; }
.side-foot .side-mode-toggle:hover { background:color-mix(in srgb,var(--hr-primary) 8%,transparent) !important; color:var(--brand-700) !important; }
.side-foot .side-lang-btn { color:#8a93a3 !important; }
.side-foot .side-lang-btn.active { background:var(--hr-primary) !important; color:#fff !important; }
.side-foot i { color:#8a93a3 !important; }
[data-theme="dark"] .sidebar { background: linear-gradient(#111c30 0%,#0c1320 100%) !important; border-right:0 !important; box-shadow:none !important; }
[data-theme="dark"] .sidebar .nav-section { color:var(--side-muted) !important; }
[data-theme="dark"] .sidebar a.nav-item { color:var(--side-text) !important; }
[data-theme="dark"] .sidebar a.nav-item i { color:var(--side-muted) !important; }
[data-theme="dark"] .sidebar .brand { color:#fff !important; }
[data-theme="dark"] .side-foot { background:#0a111e !important; border-top:1px solid rgba(255,255,255,.07) !important; }
[data-theme="dark"] .side-foot, [data-theme="dark"] .side-foot * { color:var(--side-text) !important; }
[data-theme="dark"] .side-foot i { color:var(--side-muted) !important; }
.sidebar a.nav-item:hover { background:var(--side-hover) !important; color:var(--side-active-tx) !important; }
.sidebar a.nav-item:hover i { color:var(--hr-primary) !important; }
[data-theme="dark"] .sidebar a.nav-item:hover i { color:var(--brand-500) !important; }
.sidebar a.nav-item.active { background:color-mix(in srgb,var(--hr-primary) 12%,transparent) !important; color:var(--side-active-tx) !important; font-weight:700; }
.sidebar a.nav-item.active i { color:var(--hr-primary) !important; }
.sidebar a.nav-item.active::before { display:block !important; background:var(--hr-primary) !important; box-shadow:0 0 8px 0 color-mix(in srgb,var(--hr-primary) 60%,transparent) !important; }
[data-nav-style="pill"] .sidebar a.nav-item { border-radius:999px !important; }
[data-nav-style="pill"] .sidebar a.nav-item.active { background:var(--hr-primary) !important; color:#fff !important; font-weight:700; }
[data-nav-style="pill"] .sidebar a.nav-item.active i { color:#fff !important; }
[data-nav-style="pill"] .sidebar a.nav-item.active::before { display:none !important; }
[data-nav-style="soft"] .sidebar a.nav-item.active { background:color-mix(in srgb,var(--hr-primary) 14%,transparent) !important; color:var(--side-active-tx) !important; font-weight:700; border-radius:10px; }
[data-nav-style="soft"] .sidebar a.nav-item.active i { color:var(--hr-primary) !important; }
[data-nav-style="soft"] .sidebar a.nav-item.active::before { display:none !important; }
@media (min-width:992px) and (prefers-reduced-motion:no-preference) {
  .sidebar a.nav-item { transition:background .18s ease,color .18s ease,transform .18s cubic-bezier(.2,.7,.3,1) !important; }
  .sidebar a.nav-item i { transition:color .18s ease,transform .22s cubic-bezier(.2,.7,.3,1) !important; }
  .sidebar a.nav-item:hover { transform:translateX(3px) !important; }
  .sidebar a.nav-item:hover i { transform:scale(1.18) !important; }
  .sidebar a.nav-item.active::before { animation:yhrPulse 2.4s ease-in-out infinite !important; }
}
[data-nav-style="pill"] .sidebar a.nav-item.active::before,[data-nav-style="soft"] .sidebar a.nav-item.active::before { animation:none !important; }
@keyframes yhrPulse { 0%,100%{box-shadow:0 0 6px 0 color-mix(in srgb,var(--hr-primary) 45%,transparent);} 50%{box-shadow:0 0 12px 1px color-mix(in srgb,var(--hr-primary) 75%,transparent);} }

/* =====================================================================
   D) HELP OVERLAY — brand + theme aware (overrides help.js injected <style>).
   help.js appends its <style> (#yhrStyle) to <head> and hard-codes a dark
   tooltip/panel; here we re-skin to var(--hr-primary) and make LIGHT the
   default (no scope) with dark under [data-theme=dark] — the app's explicit
   theme — so the help launcher/panel/tooltip/spotlight follow the chosen
   brand + theme. IDs: yhrQ(launcher) yhrPanel yhrTip yhrSpot yhrBackdrop.
   ===================================================================== */
/* brand accents (theme-independent) */
#yhrQ { background: var(--hr-primary) !important; border-color: var(--hr-primary) !important; box-shadow: 0 2px 6px var(--brand-shadow) !important; }
#yhrQ.float { box-shadow: 0 4px 12px var(--brand-shadow) !important; }
#yhrQ:hover { background: var(--hr-primary-hover, var(--hr-primary)) !important; }
#yhrSpot { border-color: var(--hr-primary) !important; box-shadow: 0 0 0 6px color-mix(in srgb,var(--hr-primary) 35%,transparent) !important; }
#yhrTip .n, #yhrTip .pri, #yhrPanel .ph, #yhrPanel .rolesel button.on, #yhrPanel li.on .n { background: var(--hr-primary) !important; }
#yhrPanel .ph .lang button.on, #yhrPanel li.on small { color: var(--hr-primary) !important; }

/* tooltip — LIGHT by default (white surface, dark ink) */
#yhrTip { background: #fff !important; color: #1f2937 !important; border: 1px solid #e5e7eb !important; color-scheme: light !important; }
#yhrTip * { color: #1f2937 !important; }
#yhrTip .muted, #yhrTip small, #yhrTip .desc, #yhrTip p { color: #5b6472 !important; }
#yhrTip .pri, #yhrTip .pri * { color: #fff !important; }
#yhrTip .sec { background: #f3f4f6 !important; border-color: #e5e7eb !important; } /* Back button — light surface in light mode (เดิม help.js ฝัง #374151 มืดค้าง) */
#yhrTip .sec, #yhrTip .sec * { color: #374151 !important; }

/* panel — LIGHT by default (follows theme tokens; tokens are light by default) */
#yhrPanel { background: #fff !important; color: #111827 !important; border-color: #e5e7eb !important; color-scheme: light !important; }
#yhrPanel .viewas { color: var(--muted, #6b7280) !important; }
#yhrPanel .rolesel { background: var(--surface-3, #f3f4f6) !important; border-color: var(--border, #e5e7eb) !important; }
#yhrPanel .rolesel button { color: var(--muted, #6b7280) !important; }
#yhrPanel .empty { color: var(--muted, #6b7280) !important; }
#yhrPanel li:hover { background: var(--brand-soft, #f5f3ff) !important; }
#yhrPanel li.on { background: var(--brand-soft, #eef2ff) !important; }
#yhrPanel li b { color: var(--text, #111827) !important; }
#yhrPanel li small { color: var(--muted, #6b7280) !important; }
#yhrPanel li .n { background: var(--brand-soft-2, #c7d2fe) !important; color: var(--brand-700, #3730a3) !important; }

/* dark — only under the app's explicit theme */
[data-theme="dark"] #yhrTip { background: #111827 !important; color: #fff !important; border: none !important; color-scheme: dark !important; }
[data-theme="dark"] #yhrTip * { color: #fff !important; }
[data-theme="dark"] #yhrTip .muted, [data-theme="dark"] #yhrTip small, [data-theme="dark"] #yhrTip .desc, [data-theme="dark"] #yhrTip p { color: #cbd5e1 !important; }
[data-theme="dark"] #yhrTip .pri, [data-theme="dark"] #yhrTip .pri * { color: #fff !important; }
[data-theme="dark"] #yhrTip .sec { background: #374151 !important; border-color: #374151 !important; }
[data-theme="dark"] #yhrTip .sec, [data-theme="dark"] #yhrTip .sec * { color: #cbd5e1 !important; }
[data-theme="dark"] #yhrPanel { background: #1f2937 !important; color: #f9fafb !important; border-color: #374151 !important; color-scheme: dark !important; }
[data-theme="dark"] #yhrPanel .viewas { color: #9ca3af !important; }
[data-theme="dark"] #yhrPanel .rolesel { background: #111827 !important; border-color: #374151 !important; }
[data-theme="dark"] #yhrPanel .rolesel button { color: #9ca3af !important; }
[data-theme="dark"] #yhrPanel .empty { color: #9ca3af !important; }
[data-theme="dark"] #yhrPanel li:hover { background: #374151 !important; }
[data-theme="dark"] #yhrPanel li.on { background: color-mix(in srgb,var(--hr-primary) 26%,transparent) !important; }
[data-theme="dark"] #yhrPanel li b { color: #f9fafb !important; }
[data-theme="dark"] #yhrPanel li small { color: #9ca3af !important; }
[data-theme="dark"] #yhrPanel li .n { background: var(--brand-700, #4338ca) !important; color: #fff !important; }
