/* ============================================================
   AQUA Control Center — Design System v2
   ปรับปรุง: typography ภาษาไทย, ลำดับชั้นข้อความ, ระยะห่าง,
   responsive แบบรวมศูนย์, การเข้าถึง (a11y)
   ============================================================ */

/* ---------- 1. FONTS (โหลดจากเครื่องเซิร์ฟเวอร์เอง รองรับ CSP) ---------- */
@font-face {
  font-family: 'Noto Sans Thai';
  src: url('/fonts/NotoSansThai-Regular.ttf') format('truetype');
  font-weight: 400 650;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Noto Sans Thai';
  src: url('/fonts/NotoSansThai-Bold.ttf') format('truetype');
  font-weight: 651 900;
  font-style: normal;
  font-display: swap;
}

/* ---------- 2. DESIGN TOKENS ---------- */
:root {
  color-scheme: dark;

  /* พื้นผิว */
  --bg: #071116;
  --panel: #0c1b21;
  --panel-2: #10242b;
  --surface-input: #081820;
  --surface-sunken: #08181d;
  --line: #23404a;
  --line-soft: #1a323a;

  /* ตัวอักษร — เพิ่ม contrast ให้ผ่าน WCAG AA */
  --text: #eefbfc;
  --text-2: #cfe4e8;
  --muted: #93b2ba;
  --muted-2: #7b9aa2;

  /* สีหลัก */
  --aqua: #35c7d4;
  --aqua-strong: #6ce6e8;
  --aqua-soft: #173c44;
  --danger: #ef6b78;
  --success: #41d192;
  --amber: #f2b84b;
  --blue: #6197ff;

  --surface-glow: rgba(53, 199, 212, .07);
  --shadow-card: 0 12px 32px rgba(0, 0, 0, .28);
  --shadow-pop: 0 24px 60px rgba(0, 0, 0, .45);

  /* ระยะห่าง — ใช้สเกลเดียวทั้งระบบ */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;
  --sp-8: 40px;

  --radius: 16px;
  --radius-sm: 11px;
  --radius-lg: 22px;

  /* ความกว้างบรรทัดที่อ่านสบาย */
  --measure: 74ch;

  /* Latin มาก่อน แล้วให้ไทยตกมาที่ Noto Sans Thai เสมอ */
  font-family: Inter, "Noto Sans Thai", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
}

/* ---------- 3. BASE + TYPOGRAPHY ---------- */
* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 82% -8%, #16434b 0, transparent 30rem),
    radial-gradient(circle at 8% 100%, #0b252c 0, transparent 24rem),
    var(--bg);
  color: var(--text);
  /* ไทยต้องการ line-height สูงกว่า latin เพราะมีสระบน–ล่างและวรรณยุกต์ */
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ห้ามใช้ letter-spacing ติดลบกับข้อความไทย — วรรณยุกต์จะชนกัน */
h1, h2, h3, h4 {
  margin-top: 0;
  letter-spacing: 0;
  line-height: 1.35;
  text-wrap: balance;
}
h1 { margin-bottom: var(--sp-1); font-size: clamp(22px, 2.4vw, 30px); font-weight: 800; }
h2 { margin-bottom: var(--sp-1); font-size: 18px; font-weight: 750; }
h3 { font-size: 15px; font-weight: 750; }
p  { margin-top: 0; }

/* ตัดคำไทยให้สวยขึ้น + กันข้อความยาว ๆ (ID, URL) ล้นกล่อง */
p, span, strong, small, li, td, th, label, summary, .answer p {
  overflow-wrap: break-word;
  word-break: normal;
  line-break: loose;
}

.eyebrow {
  margin: 0 0 var(--sp-1);
  color: var(--aqua);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
  line-height: 1.4;
  text-transform: uppercase;
}

.muted, .section-head p, .status-banner p { color: var(--muted); }

/* ความยาวบรรทัดของข้อความอธิบาย ไม่ให้ยาวจนอ่านยาก */
.section-head p, .hint, .status-banner p, .muted, .notice-box {
  max-width: var(--measure);
}

.hint { margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.7; }

.stack { display: grid; gap: var(--sp-4); }
.gap-lg { gap: var(--sp-6); }

[hidden] { display: none !important; }

/* โฟกัสที่มองเห็นชัด สำหรับผู้ใช้คีย์บอร์ด */
:focus-visible {
  outline: 2px solid var(--aqua-strong);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Scrollbar ให้เข้าธีม */
* { scrollbar-width: thin; scrollbar-color: #2a4d57 transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { border: 3px solid transparent; border-radius: 999px; background: #2a4d57; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: #37656f; background-clip: content-box; }

.skip-link {
  position: absolute; left: -9999px; top: 8px; z-index: 200;
  padding: 10px 16px; border-radius: 10px; color: #031114; background: var(--aqua-strong); font-weight: 800;
}
.skip-link:focus { left: 8px; }

/* ---------- 4. FORM CONTROLS ---------- */
button, input, textarea, select { font: inherit; font-family: inherit; }
button { cursor: pointer; }

/* หัวข้อ label กับคำอธิบายอยู่บรรทัดเดียวกัน แล้วช่องกรอกขึ้นบรรทัดใหม่เต็มความกว้าง */
label {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--sp-1) var(--sp-2);
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.5;
}
label > small { flex: 0 1 auto; color: var(--muted); font-size: 12px; font-weight: 500; }
label > input,
label > textarea,
label > select,
label > datalist,
label > .time24-picker,
label > .chip-list {
  flex: 1 0 100%;
  margin-top: var(--sp-1);
}
label > input + small,
label > select + small,
label > textarea + small { flex: 1 0 100%; margin-top: var(--sp-1); }

input, textarea, select {
  width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: 0;
  color: var(--text);
  background: linear-gradient(180deg, #0a1b20, #07151a);
  transition: border-color .18s, box-shadow .18s, background .18s;
}
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input:hover, textarea:hover, select:hover { border-color: #2f5b66; }
input:focus, textarea:focus, select:focus { border-color: var(--aqua); box-shadow: 0 0 0 3px #35c7d426; }
input:invalid:not(:placeholder-shown) { border-color: #7d3340; }
select option, select optgroup { color: #102229; background: #f7fbfc; }
select option:checked, select option:hover { color: #fff; background: #198c9a; }
textarea { min-height: 88px; resize: vertical; line-height: 1.65; }
input[type="number"] { font-variant-numeric: tabular-nums; }
input[type="file"] { padding: 9px 12px; }
input[type="color"] { width: 46px; min-height: 40px; padding: 3px; cursor: pointer; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--aqua); }
input[type="hidden"] { display: none; }

fieldset {
  display: grid;
  gap: var(--sp-2);
  margin: 0;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(8, 24, 29, .45);
}
fieldset legend {
  padding: 0 var(--sp-2);
  color: var(--aqua);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}
fieldset label { display: flex; flex-wrap: nowrap; align-items: center; gap: var(--sp-2); font-weight: 600; }
/* รายการติ๊กถูกยาว ๆ เรียงเป็นคอลัมน์เดียวจะสูงมากจนต้องเลื่อนหา จัดเป็นสองคอลัมน์แทน */
fieldset.check-columns { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: var(--sp-2) var(--sp-4); }
fieldset.check-columns legend { grid-column: 1 / -1; }
fieldset input { width: auto; }
fieldset label > input { flex: 0 0 auto; width: auto; margin-top: 0; }
.radio-label, .check-label { display: flex; flex-wrap: nowrap; align-items: center; gap: var(--sp-2); white-space: nowrap; }
.check-label { padding-bottom: 10px; }
.check-label input, .radio-label input { width: auto; flex: 0 0 auto; }

.remember-row {
  display: flex; flex-wrap: nowrap; align-items: center; gap: var(--sp-2);
  color: var(--muted); font-weight: 600; font-size: 13px;
}
.remember-row input { flex: 0 0 auto; width: 18px; height: 18px; margin-top: 0; }

.toggle-row {
  display: flex; flex-wrap: nowrap; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-input);
}
.switch { display: inline-block; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { position: relative; display: block; width: 50px; height: 28px; border-radius: 999px; background: #294047; transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + span { background: var(--aqua); }
.switch input:checked + span::after { transform: translateX(22px); }
.switch input:focus-visible + span { outline: 2px solid var(--aqua-strong); outline-offset: 3px; }

.error { min-height: 20px; margin: 0; color: var(--danger); font-size: 13px; line-height: 1.5; }

/* ---------- 5. BUTTONS ---------- */
button, .button-link {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 750;
  line-height: 1.3;
  text-decoration: none;
  white-space: nowrap;
  transition: transform .14s, filter .14s, background .16s, border-color .16s;
}
button:not(:disabled):hover, .button-link:hover { transform: translateY(-1px); filter: brightness(1.08); }
button:not(:disabled):active, .button-link:active { transform: translateY(0); }
button:disabled { opacity: .45; cursor: not-allowed; }

.primary   { color: #031114; background: var(--aqua); box-shadow: 0 6px 18px rgba(53, 199, 212, .18); }
.primary:hover { background: var(--aqua-strong); }
.secondary { background: #17323a; border-color: #2b5762; }
.secondary:hover { background: #1d3f49; }
.ghost     { background: transparent; color: var(--muted); border-color: transparent; }
.ghost:hover { color: var(--text); background: #14282f; }
.danger    { color: #ffadb6; background: #3b1b22; border-color: #5d2b34; }
.success   { color: #86eebd; background: #123d2c; border-color: #1d5b43; }
.wide      { width: 100%; }
.text-button { min-height: 34px; padding: 4px 8px; color: var(--aqua); background: transparent; }
.text-button:hover { background: #12303760; }
.icon-button {
  min-height: 38px; width: 38px; padding: 0;
  color: var(--muted); background: transparent; font-size: 24px; line-height: 1;
}
.icon-button:hover { color: var(--text); background: #14282f; }
/* ปุ่มไอคอนสี่เหลี่ยมมุมมน ใช้ SVG แทนอักขระพิเศษ เพราะฟอนต์ไทยไม่มี glyph พวกลูกศรวน
   ทำให้เบราว์เซอร์ไปหยิบฟอนต์สำรองมาแทน ขนาดและเส้นจึงเพี้ยนไปคนละแบบ */
.icon-only {
  display: inline-grid; place-items: center;
  width: 42px; min-width: 42px; height: 42px; padding: 0;
  border-radius: 11px; font-size: 0; line-height: 0;
}
.icon-only svg { display: block; }
.icon-only.is-busy { opacity: .6; cursor: wait; }
.icon-only.is-busy svg { animation: aqua-spin .9s linear infinite; }
@keyframes aqua-spin { to { transform: rotate(360deg); } }
.icon-only.secondary { color: var(--text-2); }
.icon-only.secondary:hover { color: var(--aqua-strong); }
.icon-only.danger { color: #ff9eaa; background: #3b1b22; border-color: #5d2b34; }
.icon-only.danger:hover { color: #fff; background: #55232c; border-color: #7d3340; }

/* ---------- 6. LOGIN ---------- */
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: var(--sp-6); }
.login-card {
  width: min(420px, 100%);
  padding: clamp(28px, 5vw, 44px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(150deg, rgba(16, 36, 43, .98), rgba(8, 22, 27, .98));
  box-shadow: var(--shadow-pop);
}
.login-card h1 { margin-bottom: var(--sp-2); }
.login-card > .muted { margin-bottom: var(--sp-6); font-size: 14px; }
.login-card .stack { gap: var(--sp-4); }
.brand-mark {
  display: grid; place-items: center;
  width: 54px; height: 54px; margin-bottom: var(--sp-5);
  border-radius: 17px 17px 17px 4px;
  color: #061014; font-size: 26px; font-weight: 900;
  background: linear-gradient(135deg, var(--aqua-strong), var(--aqua));
  box-shadow: 0 12px 32px #35c7d433;
}
.brand-mark.small { width: 40px; height: 40px; margin: 0; border-radius: 12px 12px 12px 4px; font-size: 19px; }

/* ---------- 7. APP SHELL ---------- */
.app-shell { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0;
  display: flex; flex-direction: column;
  height: 100vh; overflow-y: auto;
  padding: var(--sp-6) var(--sp-4) var(--sp-4);
  border-right: 1px solid var(--line);
  background: #08151af2;
  backdrop-filter: blur(16px);
}
.brand-row { display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-2) var(--sp-6); }
.brand-row strong { display: block; font-size: 17px; letter-spacing: .06em; line-height: 1.2; }
.brand-row span { display: block; color: var(--muted-2); font-size: 9.5px; letter-spacing: .14em; line-height: 1.4; }

nav { display: grid; gap: var(--sp-1); }
.nav-section { border-radius: var(--radius-sm); }
.nav-section[hidden] { display: none; }
.nav-group {
  position: relative; display: block; margin: 0;
  padding: 10px 32px 10px 10px;
  border-radius: 9px;
  color: #83a3ab;
  font-size: 10.5px; font-weight: 850; letter-spacing: .07em; line-height: 1.5;
  text-transform: uppercase;
  cursor: pointer; list-style: none;
  transition: color .16s, background .16s;
}
.nav-group::-webkit-details-marker { display: none; }
.nav-group:hover { color: #c8eef0; background: #0c2027; }
.nav-group::after {
  content: "›"; position: absolute; right: 12px; top: 50%;
  transform: translateY(-50%); color: var(--aqua); font-size: 19px;
  transition: transform .18s;
}
.nav-section[open] > .nav-group { color: #c8eef0; background: #0d252c; }
.nav-section[open] > .nav-group::after { transform: translateY(-50%) rotate(90deg); }
.nav-submenu { display: grid; gap: 3px; padding: var(--sp-1) 0 var(--sp-2) var(--sp-2); }
.nav-item {
  justify-content: flex-start;
  min-height: 38px;
  padding: 9px 11px;
  border: 1px solid transparent;
  color: var(--muted);
  background: transparent;
  font-size: 13px; font-weight: 600;
  text-align: left;
  white-space: normal;      /* เมนูไทยยาว ๆ ให้ตัดบรรทัดได้ ไม่ล้น */
  line-height: 1.45;
  transition: color .16s, background .16s, border-color .16s, transform .16s;
}
.nav-item:hover { color: var(--text); background: #143139; border-color: #28515b; transform: translateX(2px); }
.nav-item.active {
  color: var(--text); background: #143139;
  border-color: #28515b; box-shadow: inset 3px 0 var(--aqua);
  font-weight: 750;
}
.nav-notice {
  display: inline-grid; place-items: center; flex: 0 0 auto;
  min-width: 19px; height: 19px; margin-left: auto; padding: 0 6px;
  border-radius: 999px; color: #fff; background: #e75252;
  font-size: 10.5px; font-weight: 900; line-height: 1;
}
.nav-notice[hidden] { display: none; }

.sidebar-foot {
  display: flex; align-items: center; gap: var(--sp-2);
  margin-top: auto; padding: var(--sp-3) var(--sp-2) 0;
  border-top: 1px solid var(--line-soft);
  color: var(--muted); font-size: 12px;
}
.sidebar-foot > div { min-width: 0; }
.sidebar-foot span, .sidebar-foot small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot small { margin-top: 2px; color: var(--muted-2); }
.dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 10px currentColor; }
.dot.online { background: var(--success); }

.nav-toggle { display: none; }
.nav-scrim {
  position: fixed; inset: 0; z-index: 50;
  background: #02080bb8; backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none; transition: opacity .22s;
}

/* ---------- 8. WORKSPACE + TOPBAR ---------- */
.workspace {
  min-width: 0;
  padding: 0 clamp(16px, 2.4vw, 36px) 72px;
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  padding: var(--sp-4) 0 var(--sp-3);
  border-bottom: 1px solid rgba(35, 64, 74, .8);
  background: linear-gradient(180deg, rgba(7, 17, 22, .97) 72%, rgba(7, 17, 22, .78));
  backdrop-filter: blur(12px);
}
.topbar-lead { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.topbar-lead > div { min-width: 0; }
.topbar h1 { margin: 0; text-shadow: 0 0 26px rgba(108, 230, 232, .12); }
.top-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.global-search { width: clamp(150px, 18vw, 230px); min-height: 40px; }
.live-pill {
  display: inline-flex; align-items: center;
  padding: 5px 11px;
  border: 1px solid #35c7d442; border-radius: 999px;
  color: var(--aqua-strong); background: #35c7d417;
  font-size: 11.5px; font-weight: 800; line-height: 1.4;
}
.realtime-pill { white-space: nowrap; }
.realtime-pill.offline { color: var(--amber); border-color: #e6ad4f66; background: #e6ad4f17; }

/* ---------- 9. PANELS, CARDS, SECTION HEADS ---------- */
.panel-view { display: grid; gap: var(--sp-4); align-content: start; }
.panel-view:not([hidden]) { animation: aqua-enter .26s ease-out; }

.card, .stat {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0c1b21e8;
  box-shadow: var(--shadow-card);
  transition: border-color .18s, transform .18s, box-shadow .18s;
}
.card { padding: clamp(16px, 1.7vw, 22px); }
.card:hover { border-color: #2d5660; }

/* หัวข้อส่วน: ชื่อเรื่องกับคำอธิบายจับกลุ่มกัน ปุ่มอยู่ขวา */
.section-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-4);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--line-soft);
}
.section-head > div:first-child { min-width: 0; }
.section-head h2 { margin-bottom: 3px; }
.section-head p { margin: 0; font-size: 12.5px; line-height: 1.65; }
.section-head.outside { margin-top: var(--sp-5); margin-bottom: var(--sp-3); padding-bottom: 0; border-bottom: 0; }
.section-head.wrap { flex-wrap: wrap; }
.section-head .filters, .section-head .top-actions { flex: 0 0 auto; }
.section-head > input[type="color"] { flex: 0 0 auto; align-self: center; }
/* ช่องเลือกสีเดี่ยว ๆ ในหัวการ์ดควรมีคำกำกับ ไม่ใช่กล่องสีลอย ๆ */
.color-field { display: flex; flex: 0 0 auto; align-items: center; gap: var(--sp-2); font-size: 12.5px; font-weight: 700; color: var(--text-2); white-space: nowrap; }
.color-field input[type="color"] { flex: 0 0 auto; margin-top: 0; }
/* หัวข้อรองที่อยู่กลางการ์ด ไม่ต้องมีเส้นคั่นซ้ำ */
.card > .section-head ~ .section-head { margin-top: var(--sp-6); }
.panel-view > .section-head.outside + * { margin-top: 0; }
.panel-message-card { margin-top: 0; }

.two-col   { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3) var(--sp-4); align-items: start; }
.three-col { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-3) var(--sp-4); align-items: start; }
.two-col.compact { gap: var(--sp-3) var(--sp-4); }
.account-layout { align-items: start; }
.rank-card { margin-bottom: 0; }
.duty-card { margin-top: 0; }

/* แถบเครื่องมือหัวการ์ด
   input/select ตั้ง width:100% ไว้เป็นค่าเริ่มต้น ถ้าไม่รีเซ็ตจะกินเต็มบรรทัดแล้วดันตัวอื่นตกบรรทัด
   ปุ่มถูกจัดเป็นกลุ่มเดียวกันเสมอ จะได้ไม่มีปุ่มหลุดไปอยู่บรรทัดล่างตัวเดียว */
.filters { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--sp-2); }
.filters > input, .filters > select, .filters > button { width: auto; min-height: 40px; }
.filters > input { flex: 0 1 240px; min-width: 170px; }
.filters > select { flex: 0 1 auto; min-width: 160px; }
.filter-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.filter-actions > button { min-height: 40px; }
.compact-search { width: min(300px, 100%); }
.wrap { flex-wrap: wrap; }
.right-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-4); }
/* .stack เป็น grid ปุ่มที่เป็นลูกโดยตรงจึงถูกยืดเต็มความกว้างจนดูเหมือนแถบ ไม่ใช่ปุ่ม */
.stack > button:not(.wide) { justify-self: end; }

.notice-box {
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid #2a5660; border-left: 3px solid var(--aqua);
  border-radius: var(--radius-sm);
  color: #bceef0; background: #102a31;
  font-size: 13px; line-height: 1.7;
}

/* แถบบันทึกลอยอยู่เหนือเนื้อหา ถ้าไม่เผื่อระยะไว้ มันจะบังช่องกรอกแถวสุดท้ายตลอดเวลา
   จนผู้ใช้เลื่อนยังไงก็ไม่เห็น จึงเว้นระยะให้การ์ดก่อนหน้าเสมอ */
.save-bar {
  position: sticky; bottom: var(--sp-4); z-index: 15;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-4);
  margin-top: var(--sp-5);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid #34717a; border-radius: 14px;
  background: #0b2027f2;
  box-shadow: 0 12px 34px #0008;
  backdrop-filter: blur(14px);
}
.save-bar span { color: var(--muted); font-size: 12.5px; }
/* เว้นที่ให้เนื้อหาเลื่อนพ้นแถบบันทึกได้ */
.card + .save-bar, form > .card:last-of-type { scroll-margin-bottom: 88px; }
.save-bar ~ *, form:has(> .save-bar) > .card:last-of-type { margin-bottom: 0; }
form:has(> .save-bar) > .card:last-of-type, section:has(> .save-bar) > .card:last-of-type { padding-bottom: 84px; }
.save-bar span.saved { color: var(--success); font-weight: 750; }
.save-bar span.saving { color: var(--amber); }
button.is-saving { opacity: .7; cursor: wait; }

/* ---------- 10. STATUS BANNER + STATS ---------- */
.status-banner {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-5);
  padding: clamp(22px, 3vw, 34px);
  border: 1px solid #24515a; border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 85% 50%, #35c7d426, transparent 18rem),
    linear-gradient(135deg, #102a31, #0a1a20);
  overflow: hidden;
}
.status-banner > div:first-child { min-width: 0; }
.status-banner .live-pill { margin-bottom: var(--sp-3); }
.status-banner h2 { margin-bottom: var(--sp-2); font-size: clamp(21px, 3vw, 30px); }
.status-banner p { margin: 0; font-size: 13.5px; line-height: 1.7; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-3); }
.stat { padding: var(--sp-4); box-shadow: inset 0 3px var(--aqua), var(--shadow-card); }
.stat.amber { box-shadow: inset 0 3px var(--amber), var(--shadow-card); }
.stat.blue  { box-shadow: inset 0 3px var(--blue), var(--shadow-card); }
.stat.green { box-shadow: inset 0 3px var(--success), var(--shadow-card); }
.stat:hover { transform: translateY(-2px); }
.stat span { display: block; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.stat strong { display: block; margin-top: var(--sp-2); font-size: clamp(26px, 3vw, 32px); font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; }

/* ---------- 11. LISTS + ROWS ---------- */
.application-list, .approval-list, .account-list, .slot-list, .evidence-list { display: grid; gap: var(--sp-2); }

.application-row, .payroll-row, .duty-row, .approval-row, .account-row {
  display: grid; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3);
  border: 1px solid transparent; border-bottom-color: var(--line-soft);
  transition: background .16s, border-color .16s;
}
.application-row:hover, .payroll-row:hover, .duty-row:hover, .approval-row:hover {
  border-color: #274650; border-radius: var(--radius-sm); background: #102229;
}
.application-row  { grid-template-columns: 60px minmax(180px, 1fr) max-content minmax(0, 1fr) max-content; }
/* คอลัมน์ชื่อจำกัดความกว้าง เพื่อให้กลุ่มข้อมูลขยับมาชิดชื่อ ไม่ลอยกลางแถว */
.employee-row     { grid-template-columns: 74px minmax(0, 240px) minmax(0, 1fr) max-content; gap: var(--sp-4); }
.evaluation-row   { grid-template-columns: 74px minmax(0, 220px) minmax(0, 1fr) max-content max-content; gap: var(--sp-4); }
.employee-row, .evaluation-row { align-items: center; padding: var(--sp-4) var(--sp-3); }
.payroll-row  { grid-template-columns: minmax(180px, 1.5fr) 130px 165px 130px 120px auto; }
.duty-row     { grid-template-columns: minmax(180px, 1.3fr) 100px minmax(200px, 1.2fr) 140px minmax(160px, .8fr) auto; }
.approval-row { grid-template-columns: minmax(220px, 1fr) auto auto auto; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-sunken); }
.account-row  { grid-template-columns: minmax(0, 1fr) auto auto auto auto; padding: var(--sp-3) var(--sp-4); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-sunken); }

.application-id { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.application-user { min-width: 0; }
.application-user strong { display: block; font-size: 14.5px; line-height: 1.4; }
.application-user span, .application-date { display: block; color: var(--muted); font-size: 12.5px; line-height: 1.7; }
.application-user strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.application-meta { display: grid; gap: 2px; min-width: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.application-meta span { color: var(--aqua); font-size: 10.5px; font-weight: 700; letter-spacing: .03em; }
.application-meta strong { color: var(--text); font-size: 12px; font-weight: 600; }

.employee-current, .employee-duty { display: grid; gap: 3px; min-width: 0; font-size: 12px; }
.employee-current span, .employee-duty span { color: var(--aqua); font-size: 10.5px; font-weight: 700; }
.employee-current strong, .employee-duty strong { color: var(--text); font-size: 13px; }

/* ข้อมูลย่อยแบบบรรทัดเดียว — ให้ตัดบรรทัดได้ ไม่ล้นออกนอกการ์ด */
.inline-record-data {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 4px var(--sp-3);
  min-width: 0;
  color: var(--muted); font-size: 12px; line-height: 1.6;
}
.inline-record-data span { white-space: nowrap; }
.inline-record-data span + span::before { content: '·'; margin-right: var(--sp-3); color: #37606b; }
.inline-record-data b { color: var(--text); font-weight: 650; }

/* ข้อมูลประจำแถว: หัวข้อเล็กด้านบน ค่าตัวหนาด้านล่าง จัดชิดซ้ายเป็นคอลัมน์
   อ่านง่ายและกวาดตาเทียบระหว่างแถวได้ ไม่ต้องไล่อ่านข้อความยาวคั่นด้วยจุด */
.record-facts {
  display: flex; flex-wrap: wrap; align-items: flex-start;
  gap: var(--sp-3) var(--sp-5);
  min-width: 0;
}
.record-facts .fact {
  display: grid; gap: 1px; min-width: 0;
  padding-left: var(--sp-3);
  border-left: 2px solid #234750;
}
.record-facts .fact > span {
  color: var(--muted); font-size: 11px; font-weight: 600;
  letter-spacing: .02em; line-height: 1.4; white-space: nowrap;
}
.record-facts .fact > strong {
  color: var(--text); font-size: 14px; font-weight: 750; line-height: 1.45;
  overflow-wrap: break-word;
}
.record-facts .fact.num > strong { font-variant-numeric: tabular-nums; }
.record-facts .fact.good > strong { color: #8bebc0; }
.record-facts .fact.warn > strong { color: var(--amber); }
.record-facts .fact.bad  > strong { color: #ff9eaa; }
.record-facts .fact.good { border-left-color: #2c6d54; }
.record-facts .fact.warn { border-left-color: #6d5622; }
.record-facts .fact.bad  { border-left-color: #6b2f38; }

.payroll-row div strong, .payroll-row div span,
.duty-row div strong, .duty-row div span,
.approval-row div strong, .approval-row div span,
.account-row strong, .account-row span { display: block; }
.payroll-row div span, .duty-row div span, .approval-row div span, .account-row span {
  margin-top: var(--sp-1); color: var(--muted); font-size: 12px; line-height: 1.65;
}
.payroll-row > span, .payroll-row > strong { font-size: 12.5px; line-height: 1.6; font-variant-numeric: tabular-nums; }
.log-warning { color: var(--amber); font-size: 11px; line-height: 1.5; }
.audit-detail { display: block; margin-top: var(--sp-1); color: var(--aqua-strong); font-size: 12px; line-height: 1.6; }

.employee-row .application-id { color: var(--aqua); font-weight: 750; }
.employee-row .application-user { display: grid; justify-items: start; gap: var(--sp-1); }
.employee-row .application-user strong, .evaluation-row .application-user strong { font-size: 15.5px; }
.employee-row .application-user span, .evaluation-row .application-user span { font-size: 12px; }

.badge {
  display: inline-flex; align-items: center; width: fit-content;
  padding: 5px 10px;
  border: 1px solid rgba(255, 215, 121, .22); border-radius: 999px;
  color: #ffd779; background: #473714;
  font-size: 11.5px; font-weight: 750; line-height: 1.4; white-space: nowrap;
}
.badge.interview { color: #94b9ff; background: #152f5a; border-color: #94b9ff33; }
.badge.approved  { color: #83e7b6; background: #133b2b; border-color: #83e7b633; }
.badge.rejected  { color: #ff9eaa; background: #421c24; border-color: #ff9eaa33; }
.rank-chip {
  display: inline-flex; padding: 4px 10px;
  border: 1px solid #3bbbc8; border-radius: 999px;
  color: #8df3ed !important; background: #12343b;
  font-size: 10.5px !important; font-weight: 850; letter-spacing: .04em;
}

.empty {
  padding: clamp(32px, 6vw, 52px) var(--sp-5);
  border: 1px dashed #2b5761; border-radius: 14px;
  background: linear-gradient(135deg, rgba(16, 42, 49, .55), rgba(8, 24, 29, .3));
  color: var(--muted); font-size: 13.5px; text-align: center; line-height: 1.7;
}

/* แถบสรุปสถานะ ใช้สีและจุดบอกสถานะแทนการให้ผู้ใช้ไปตีความตัวเลขเอง */
.status-strip {
  display: flex; align-items: center; gap: var(--sp-3);
  margin-bottom: var(--sp-4); padding: var(--sp-4);
  border: 1px solid var(--line); border-left: 3px solid var(--muted);
  border-radius: var(--radius-sm); background: var(--surface-sunken);
}
.status-strip > div { min-width: 0; }
.status-strip strong { display: block; font-size: 15px; line-height: 1.45; }
.status-strip span:not(.dot) { display: block; margin-top: 2px; color: var(--muted); font-size: 12.5px; line-height: 1.6; overflow-wrap: anywhere; }
.status-strip .dot { width: 11px; height: 11px; }
.status-strip.online { border-left-color: var(--success); background: #10281f; }
.status-strip.online .dot { background: var(--success); }
.status-strip.warn { border-left-color: var(--amber); background: #2a2113; }
.status-strip.warn .dot { background: var(--amber); }
.status-strip.offline { border-left-color: var(--danger); background: #2b171c; }
.status-strip.offline .dot { background: var(--danger); }
.status-strip + .stats-grid { margin-top: 0; }

/* ---------- 12. FORM BUILDER / ROUTES / SLOTS / RANKS ---------- */
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); }
.field-card { display: grid; gap: var(--sp-4); padding: var(--sp-5); border: 1px solid var(--line); border-radius: 14px; background: #0b1a1f; }
.field-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.field-number { color: var(--aqua); font-size: 11.5px; font-weight: 800; letter-spacing: .1em; }
.field-options { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-3); align-items: end; }
.choice-options { display: grid; gap: var(--sp-3); }

.route-list { display: grid; gap: var(--sp-4); }
.route-card { display: grid; gap: var(--sp-4); padding: var(--sp-4); border: 1px solid var(--line); border-radius: 14px; background: var(--surface-sunken); }
.route-card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.route-grid { display: grid; grid-template-columns: minmax(140px, .7fr) minmax(200px, 1fr) minmax(200px, 1fr); gap: var(--sp-3); }
.route-status { color: var(--muted); font-size: 12px; line-height: 1.6; }

.inline-add { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-2); }
/* แถวสำหรับเพิ่มรายการใหม่ ใช้ร่วมกันหลายที่และมีจำนวนช่องไม่เท่ากัน
   ของเดิมกำหนดเป็น grid 3 คอลัมน์ตายตัว พอมี 4 ช่องปุ่มจะตกลงไปยืดเต็มบรรทัดล่าง */
.slot-add { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-2) var(--sp-3); }
.slot-add > input { flex: 1 1 200px; min-width: 150px; }
.slot-add > input[type="number"] { flex: 0 0 130px; min-width: 110px; }
.slot-add > label { flex: 0 1 auto; }
.slot-add > button { flex: 0 0 auto; margin-left: auto; }
.slot-row {
  display: grid; grid-template-columns: minmax(200px, 270px) minmax(200px, 270px) 180px auto;
  justify-content: start; gap: var(--sp-3); align-items: end;
  padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-sunken);
}
.reviewer-row { grid-template-columns: minmax(180px, 1fr) auto; align-items: center; }
.reviewer-row strong, .reviewer-row span { display: block; }
.reviewer-row span { margin-top: var(--sp-1); color: var(--muted); font-size: 12px; }
.multiplier-when { display: block; margin-top: var(--sp-2); }

.rank-grid { display: grid; gap: var(--sp-2); }
.rank-row  { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(170px, 1fr) minmax(140px, .7fr) max-content max-content; gap: var(--sp-2) var(--sp-3); align-items: end; }
.rank-row, .rate-row, .special-rate-row { padding: var(--sp-3) var(--sp-4); }
/* ปุ่มลบท้ายแถวต้องอยู่ระดับเดียวกับช่องกรอก ไม่ลอยขึ้นไปชิดหัวข้อ */
.rank-row > button, .rate-row > button, .special-rate-row > button, .slot-row > button { align-self: end; margin-bottom: 1px; }
.rank-row > .radio-label { align-self: end; padding-bottom: 12px; white-space: nowrap; }
.rate-row  { display: grid; grid-template-columns: repeat(4, minmax(110px, 1fr)) auto; gap: var(--sp-2); align-items: end; padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-sunken); }
.special-rate-row { display: grid; grid-template-columns: minmax(170px, 1fr) minmax(130px, .45fr) auto; gap: var(--sp-2); align-items: end; padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-sunken); }

.time-input-panel {
  display: grid; grid-template-columns: minmax(115px, 180px) auto minmax(115px, 180px);
  align-items: end; justify-content: start; gap: var(--sp-2);
  width: fit-content; max-width: 100%;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface-sunken);
  box-shadow: inset 0 1px rgba(255, 255, 255, .03);
}
.time-input-panel > span { padding-bottom: 11px; color: var(--muted); font-weight: 750; }
.time-input-panel label { min-width: 0; }
.time-input-panel input { text-align: center; font-variant-numeric: tabular-nums; }

.time24-picker { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); width: 100%; }
.time24-date { flex: 1 1 180px; }
.time24-clock { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 10px; background: #07171c; }
.time24-clock select { width: 66px; min-width: 66px; min-height: 36px; padding: 6px 8px; }
.time24-clock em { color: var(--aqua); font-size: 9.5px; font-style: normal; font-weight: 900; letter-spacing: .08em; }

.chip-list { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); min-height: 42px; }
.chip { display: inline-flex; align-items: center; gap: var(--sp-2); padding: 7px 10px; border: 1px solid #28515b; border-radius: 999px; color: #ccecef; background: #102a31; font-size: 12.5px; }
.chip button { min-height: 0; padding: 0 3px; color: var(--muted); background: transparent; font-size: 17px; line-height: 1; }

.picker-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: var(--sp-2);
  max-height: 240px; padding: 2px; overflow: auto;
}
.picker-grid label {
  display: flex; flex-wrap: nowrap; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3); border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-sunken); font-size: 13px; font-weight: 600; line-height: 1.55;
  cursor: pointer;
}
.picker-grid label:hover { border-color: #3e8490; background: #0d252c; }
.picker-grid label > input { flex: 0 0 auto; width: 18px; margin-top: 0; }
.person-picker { max-height: 320px; }
.person-option {
  align-items: flex-start; min-height: 68px;
  transition: border-color .16s, background .16s, box-shadow .16s;
}
.person-option > span { flex: 1 1 auto; min-width: 0; }
.person-option:hover { border-color: #3e8490; background: #0d252c; }
.person-option.selected { border-color: #45d49a; background: #12382d; box-shadow: inset 0 0 0 1px #45d49a55; }
.person-option span, .person-option strong, .person-option small { display: block; }
.person-option small { margin-top: var(--sp-1); color: var(--muted); font-size: 11.5px; line-height: 1.6; }

.danger-zone { border-color: #6f303b; background: #26151a; }
.danger-zone .section-head { border-bottom-color: #4b2530; }

/* รายการติ๊กเปิด/ปิดการขออนุมัติ — หัวข้อกับคำอธิบายจัดกลุ่มกัน ไม่ใช่ข้อความยาวบรรทัดเดียว */
.approval-toggle { align-items: flex-start !important; gap: var(--sp-3) !important; padding: var(--sp-3); border: 1px solid var(--line-soft); border-radius: 10px; background: var(--surface-sunken); cursor: pointer; }
.approval-toggle:hover { border-color: #3e8490; background: #0d252c; }
.approval-toggle > input { flex: 0 0 auto; margin-top: 3px; }
.approval-toggle > span { display: grid; gap: 2px; min-width: 0; }
.approval-toggle strong { font-size: 13.5px; font-weight: 700; line-height: 1.45; }
.approval-toggle small { color: var(--muted); font-size: 11.5px; font-weight: 500; line-height: 1.6; }
.approval-toggle:has(input:checked) { border-color: #3bbbc8; background: #12303a; }
.approval-toggle:has(input:checked) strong { color: var(--aqua-strong); }

/* กลุ่มการอนุมัติ: หัวข้อหมวด + ตัวนับ + ปุ่มเปิด/ปิดทั้งหมวด */
.approval-group { border: 1px solid var(--line); border-radius: var(--radius-sm); background: rgba(8, 24, 29, .45); overflow: hidden; }
.approval-group-head {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line-soft); background: #0d222900;
}
.approval-group-head h3 { margin: 0; color: var(--aqua); font-size: 13px; letter-spacing: .04em; text-transform: uppercase; }
.approval-group-head span { color: var(--muted); font-size: 12px; line-height: 1.5; }
.approval-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--sp-2); padding: var(--sp-3); }
.approval-toggle .risk-tag {
  justify-self: start; margin-top: 3px; padding: 2px 7px;
  border: 1px solid var(--line); border-radius: 999px;
  color: var(--muted); font-size: 10px; font-style: normal; font-weight: 800; letter-spacing: .03em;
}
.approval-toggle .risk-tag.bad { color: #ff9eaa; border-color: #6b2f38; background: #2b171c; }
.approval-toggle .risk-tag.warn { color: var(--amber); border-color: #6d5622; background: #241f13; }
.approval-toggle .risk-tag.good { color: #8bebc0; border-color: #2c6d54; background: #10281f; }
@media (max-width: 640px) { .approval-grid { grid-template-columns: minmax(0, 1fr); } }

/* การ์ดกฎ Blacklist */
.rule-card { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-sunken); overflow: hidden; }
.rule-card.is-off { opacity: .55; }
.rule-card-head {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--line-soft); background: #0d2229;
}
.rule-card-head .rule-code { flex: 0 0 96px; width: 96px; min-height: 34px; padding: 5px 9px; font-size: 12px; font-weight: 800; color: var(--aqua); text-align: center; }
.rule-card-head .rule-name { flex: 1 1 260px; min-width: 180px; min-height: 34px; padding: 5px 10px; font-weight: 700; }
.rule-card-head .check-label { flex: 0 0 auto; padding-bottom: 0; font-size: 12.5px; }
.rule-card-head .rule-remove { flex: 0 0 auto; color: #ff9eaa; }
.rule-card-body { display: grid; gap: var(--sp-3); padding: var(--sp-3); }
.rule-card-body textarea { min-height: 58px; }
@media (max-width: 640px) { .rule-card-head .rule-code, .rule-card-head .rule-name { flex: 1 1 100%; width: auto; text-align: left; } }

/* ช่องอัปโหลดโลโก้ */
.logo-uploader {
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-sunken);
}
.logo-preview {
  display: grid; place-items: center; overflow: hidden; flex: 0 0 auto;
  width: 64px; height: 64px; border-radius: 16px 16px 16px 5px;
  color: #061014; font-size: 26px; font-weight: 900;
  background: linear-gradient(135deg, var(--aqua-strong), var(--aqua));
}
.logo-preview img { width: 100%; height: 100%; object-fit: contain; background: #08151a; }
.logo-uploader-body { display: grid; gap: var(--sp-2); min-width: 0; }
.logo-uploader-body strong { font-size: 13.5px; }
label.button-link { cursor: pointer; }
@media (max-width: 640px) { .logo-uploader { flex-direction: column; align-items: flex-start; } }

/* ตัวอย่างแบรนด์ในหน้าตั้งค่าข้อมูลเว็บ */
.brand-preview {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #08151af2;
}
.brand-preview-mark {
  display: grid; place-items: center; overflow: hidden;
  width: 44px; height: 44px; border-radius: 13px 13px 13px 4px;
  color: #061014; font-size: 20px; font-weight: 900;
  background: linear-gradient(135deg, var(--aqua-strong), var(--aqua));
}
.brand-preview-mark img, .brand-row .brand-mark img { width: 100%; height: 100%; object-fit: cover; }
.brand-preview strong { display: block; font-size: 17px; letter-spacing: .06em; line-height: 1.2; }
.brand-preview span { display: block; color: var(--muted-2); font-size: 9.5px; letter-spacing: .14em; line-height: 1.4; }
.brand-row .brand-mark { overflow: hidden; }

/* ตัวเลือกสิทธิ์แบบแบ่งหมวด */
.permission-picker { display: grid; gap: var(--sp-2); }
.permission-group { border: 1px solid var(--line); border-radius: var(--radius-sm); background: rgba(8, 24, 29, .5); overflow: hidden; }
.permission-group-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-3); border-bottom: 1px solid var(--line-soft); background: #0d2229;
}
.permission-all { display: flex; align-items: flex-start; gap: var(--sp-2); min-width: 0; cursor: pointer; font-weight: 700; }
.permission-all > input { flex: 0 0 auto; margin-top: 2px; }
.permission-all span { display: grid; gap: 1px; min-width: 0; }
.permission-all strong { color: var(--aqua-strong); font-size: 13.5px; line-height: 1.4; }
.permission-all small { color: var(--muted); font-size: 11.5px; font-weight: 500; line-height: 1.55; }
.permission-count { flex: 0 0 auto; color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.permission-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: var(--sp-2); padding: var(--sp-3); }
.permission-item {
  display: flex; align-items: flex-start; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3); border: 1px solid var(--line-soft); border-radius: 9px;
  background: var(--surface-sunken); cursor: pointer; font-weight: 600;
}
.permission-item:hover { border-color: #3e8490; background: #0d252c; }
.permission-item > input { flex: 0 0 auto; margin-top: 2px; }
.permission-item span { display: grid; gap: 1px; min-width: 0; }
.permission-item strong { font-size: 12.5px; font-weight: 700; line-height: 1.4; }
.permission-item small { color: var(--muted); font-size: 11px; font-weight: 500; line-height: 1.5; }
.permission-item:has(input:checked) { border-color: #3bbbc8; background: #12303a; }
.permission-item:has(input:checked) strong { color: var(--aqua-strong); }
.permission-item.is-critical:has(input:checked) { border-color: #7d3340; background: #2b171c; }
.permission-item.is-critical:has(input:checked) strong { color: #ff9eaa; }

/* รายการชื่อที่แนะนำขณะพิมพ์ */
.suggest-list {
  display: grid; gap: 2px; margin-top: -8px; padding: var(--sp-2);
  border: 1px solid #2f5b66; border-radius: var(--radius-sm);
  background: #0b1e24; box-shadow: var(--shadow-pop);
  max-height: 240px; overflow-y: auto;
}
.suggest-item {
  display: grid; gap: 1px; justify-items: start;
  width: 100%; min-height: 0; padding: var(--sp-2) var(--sp-3);
  border: 0; border-radius: 9px; background: transparent; text-align: left;
}
.suggest-item:hover, .suggest-item:focus-visible { background: #143139; transform: none; }
.suggest-item strong { color: var(--text); font-size: 13.5px; font-weight: 700; line-height: 1.4; }
.suggest-item span { color: var(--muted); font-size: 11.5px; font-weight: 500; line-height: 1.5; }

/* ---------- 13. EXTERNAL ACCESS / WEBHOOK ---------- */
.external-access-card { display: grid; gap: var(--sp-5); }
.external-access-card .section-head { margin-bottom: 0; }
.external-overview { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-3); }
.external-fact { min-width: 0; padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-sunken); }
.external-fact span, .external-fact strong { display: block; }
.external-fact span { margin-bottom: var(--sp-2); color: var(--muted); font-size: 12px; }
.external-fact strong { overflow-wrap: anywhere; font-size: 13.5px; line-height: 1.55; }
.external-check-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); margin: 0; padding: 0; list-style: none; }
.external-check { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-sunken); }
.external-check > span { display: grid; flex: 0 0 24px; place-items: center; width: 24px; height: 24px; border-radius: 50%; font-size: 13px; font-weight: 900; }
.external-check.ok > span { color: #061610; background: var(--success); }
.external-check.warn > span { color: #241707; background: var(--amber); }
.external-check strong, .external-check small { display: block; }
.external-check strong { font-size: 13px; }
.external-check small { margin-top: 3px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.external-issues { color: #ffd2d7; border-color: #7d3340; border-left-color: var(--danger); background: #2b171c; }
.external-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-4); }
.external-actions p { margin: 0; }

.webhook-help { margin-bottom: 0; }
.webhook-help summary { cursor: pointer; font-weight: 750; }
.webhook-help pre {
  overflow: auto; margin: var(--sp-3) 0 0; padding: var(--sp-4);
  border-radius: 10px; color: #dff9fa; background: #07151a;
  font: 12.5px/1.75 ui-monospace, SFMono-Regular, Consolas, monospace;
}

/* ---------- 14. TIMELINE ---------- */
.timeline-scale { display: grid; grid-template-columns: repeat(5, 1fr); margin: 0 var(--sp-2) var(--sp-2) 210px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.timeline-scale span { text-align: center; }
.timeline-scale span:first-child { text-align: left; }
.timeline-scale span:last-child { text-align: right; }
.hr-timeline { display: grid; gap: var(--sp-2); }
.timeline-row { display: grid; grid-template-columns: 195px minmax(400px, 1fr); gap: var(--sp-3); align-items: center; }
.timeline-person { min-width: 0; }
.timeline-person strong, .timeline-person span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline-person strong { font-size: 13.5px; }
.timeline-person span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.timeline-track {
  position: relative; height: 92px; overflow: hidden;
  border: 1px solid var(--line); border-radius: 10px;
  background: repeating-linear-gradient(90deg, #0a181d 0, #0a181d calc(25% - 1px), #28434b calc(25% - 1px), #28434b 25%);
}
.timeline-block {
  position: absolute; top: 6px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  min-width: 54px; padding: 0 10px;
  border: 1px solid #78ece7; border-radius: 999px;
  color: #031114; background: linear-gradient(90deg, #35c7d4, #63e4bc);
  box-shadow: 0 5px 16px #35c7d433;
  font-size: 10.5px; font-weight: 850; white-space: nowrap;
  cursor: grab; touch-action: none; user-select: none;
}
.timeline-block-2 { top: 35px; background: linear-gradient(90deg, #65d69b, #b7e66c); }
.timeline-block-3 { top: 64px; background: linear-gradient(90deg, #f1c75b, #f09367); }
.timeline-block:active { cursor: grabbing; filter: brightness(1.12); }
.timeline-missing { display: grid; place-items: center; color: var(--danger); background: #29181d; cursor: default; }

/* ---------- 15. DIALOGS ---------- */
dialog {
  width: min(680px, calc(100% - 24px));
  max-height: min(88vh, 900px);
  padding: 0;
  border: 1px solid #2a5059; border-radius: var(--radius-lg);
  color: var(--text); background: #0b1c22;
  box-shadow: var(--shadow-pop);
}
.wide-dialog { width: min(980px, calc(100% - 24px)); }
dialog::backdrop { background: #02080bcc; backdrop-filter: blur(5px); }
.dialog-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--line);
  background: #0b1c22;
}
.dialog-head h2 { margin: 0; font-size: 19px; }
.dialog-form, #dialogBody { display: grid; gap: var(--sp-4); padding: var(--sp-5) var(--sp-6); }
.dialog-actions {
  position: sticky; bottom: 0; z-index: 2;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--line);
  background: #0b1c22;
}
.dialog-actions > .danger:first-child { margin-right: auto; }
.answer { padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-input); }
.answer span { display: block; margin-bottom: var(--sp-2); color: var(--aqua); font-size: 11.5px; font-weight: 750; letter-spacing: .03em; }
.answer p { margin: 0; line-height: 1.75; white-space: pre-wrap; }
.profile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
.evidence-link { display: block; padding: var(--sp-3); border: 1px solid #2a5059; border-radius: 10px; color: var(--aqua); background: #0d252c; overflow-wrap: anywhere; font-size: 13px; }
.evidence-link:hover { border-color: var(--aqua); background: #12323a; }
.json-editor { min-height: 280px; font: 12px/1.7 ui-monospace, SFMono-Regular, Consolas, monospace; tab-size: 2; }
.complaint-workflow { padding-top: 0; }

.permission-preview { display: grid; gap: var(--sp-3); padding: var(--sp-5) var(--sp-6); }
.permission-preview section { padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-input); }
.permission-preview h3 { margin: 0 0 var(--sp-2); color: var(--aqua); font-size: 13.5px; }
.preview-menu { padding: 7px 10px; border-left: 3px solid var(--aqua); border-radius: 0 8px 8px 0; color: #d9f2f4; background: #10242b; font-size: 13px; }
.preview-menu + .preview-menu { margin-top: 6px; }

/* ---------- 16. TOAST ---------- */
.toast {
  position: fixed; right: var(--sp-6); bottom: var(--sp-6); z-index: 100;
  max-width: min(360px, calc(100vw - 32px));
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid #2b5962; border-left: 3px solid var(--aqua); border-radius: var(--radius-sm);
  background: #113039; box-shadow: 0 16px 40px #000a;
  font-size: 13.5px; line-height: 1.6;
  opacity: 0; transform: translateY(16px); pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error-toast { border-color: #7d3340; border-left-color: var(--danger); background: #3b1b22; }

@keyframes aqua-enter { from { opacity: .55; transform: translateY(5px); } to { opacity: 1; transform: none; } }

/* ============================================================
   17. RESPONSIVE — รวมเป็นชุดเดียว ไม่ทับซ้อนกันเหมือนเดิม
   ============================================================ */

/* จอกลาง: ลดคอลัมน์ที่แน่นเกินไป */
@media (max-width: 1280px) {
  .payroll-row, .duty-row { grid-template-columns: minmax(0, 1fr); gap: var(--sp-2); }
  .payroll-row > *, .duty-row > * { grid-column: 1 / -1; }
  .payroll-row, .duty-row {
    padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--radius-sm);
    background: var(--surface-sunken);
  }
  .application-row, .employee-row, .evaluation-row { grid-template-columns: 56px minmax(0, 1fr) auto; }
  .application-meta, .employee-current, .employee-duty, .inline-record-data, .record-facts { grid-column: 2 / -1; }
  .employee-row, .evaluation-row { grid-template-columns: 60px minmax(0, 1fr) max-content; }
  .external-overview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* แท็บเล็ต + มือถือ: sidebar กลายเป็นลิ้นชักเลื่อนออก */
@media (max-width: 900px) {
  :root { font-size: 14.5px; }

  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 60;
    width: min(290px, 84vw); height: 100dvh;
    border-right: 1px solid var(--line);
    background: #08151afa;
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  .app-shell.nav-open .sidebar { transform: none; box-shadow: var(--shadow-pop); }
  .app-shell.nav-open .nav-scrim { opacity: 1; pointer-events: auto; }
  .sidebar-foot { display: flex; }
  .nav-toggle { display: inline-flex; flex: 0 0 auto; }

  .workspace { padding: 0 var(--sp-4) 72px; }
  .topbar { flex-wrap: wrap; gap: var(--sp-3); padding: var(--sp-4) 0 var(--sp-3); margin-bottom: var(--sp-5); }
  .top-actions { width: 100%; }
  .global-search { flex: 1 1 160px; width: auto; }

  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .three-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .external-check-list { grid-template-columns: minmax(0, 1fr); }
  .timeline-row { grid-template-columns: minmax(0, 1fr); }
  .timeline-scale { margin-left: 0; }
  .hr-timeline { overflow-x: auto; }
  .timeline-track { min-width: 600px; }
}

/* มือถือ */
@media (max-width: 640px) {
  .workspace { padding: 0 var(--sp-3) 64px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .topbar-lead { width: 100%; }
  .top-actions > button, .top-actions > .button-link { flex: 1 1 auto; }

  .section-head { align-items: stretch; flex-direction: column; gap: var(--sp-3); }
  .filters, .right-actions { width: 100%; }
  .filters > *, .right-actions > * { flex: 1 1 auto; }
  .filters > input, .filters > select { flex: 1 1 100%; min-width: 0; max-width: none; }
  .right-actions { justify-content: stretch; }

  .status-banner { align-items: flex-start; flex-direction: column; gap: var(--sp-4); }
  .stats-grid, .two-col, .three-col, .field-grid, .profile-grid,
  .route-grid, .external-overview, .rank-row, .rate-row, .special-rate-row,
  .slot-add, .slot-row, .inline-add, .field-options {
    grid-template-columns: minmax(0, 1fr);
  }
  .rank-row, .rate-row, .special-rate-row, .route-grid {
    padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-sunken);
  }
  .card { padding: var(--sp-4); border-radius: 14px; }

  .application-row, .approval-row, .account-row {
    grid-template-columns: minmax(0, 1fr); gap: var(--sp-2);
    padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-sunken);
  }
  .application-row > *, .approval-row > *, .account-row > * { grid-column: 1 / -1; }
  .record-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
  .record-facts .fact > span { white-space: normal; }
  .application-row > button, .approval-row > button, .account-row > button,
  .approval-row > .button-link, .account-row > .button-link { width: 100%; }
  .application-date { display: none; }

  .time-input-panel { width: 100%; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
  .dialog-head, .dialog-form, #dialogBody, .dialog-actions, .permission-preview { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .dialog-actions { display: grid; grid-template-columns: minmax(0, 1fr); }
  .dialog-actions > .danger:first-child { margin-right: 0; }
  .save-bar { bottom: var(--sp-2); }
  .toast { right: var(--sp-3); left: var(--sp-3); bottom: var(--sp-3); max-width: none; }
}

/* ---------- 18. ACCESSIBILITY ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .panel-view:not([hidden]) { animation: none; }
  button:not(:disabled):hover, .button-link:hover, .nav-item:hover, .stat:hover { transform: none; }
}

@media print {
  .sidebar, .topbar, .save-bar, .toast, .nav-scrim, .right-actions, .filters { display: none !important; }
  body { background: #fff; color: #000; }
  .card, .stat { border-color: #ccc; background: #fff; box-shadow: none; }
}
