/* ============================================================================
   Quantum Connect (Q-Connect) — Web Manager
   Pinthong Industrial · design system v2 — 2026-08-28

   CONCEPT — ยึดสัดส่วนสีจากโลโก้ "Quantum Connect" โดยตรง
     navy   #071B35  โครงสร้าง / ตัวอักษร / ปุ่มหลัก   (สีที่โลโก้ใช้มากที่สุด)
     cyan   #00A9C7  สัญญาณ / ข้อมูล / สถานะ active    (คำว่า "Connect" + วงโคจร)
     orange #FF7A1C  เฉพาะ "กำลังทำงาน / ต้องสนใจ"      (ลูกศรเคอร์เซอร์ — จุดเดียวในโลโก้)
     ice    #F4FAFC  พื้นหลัง                            (ไทล์ไอคอน)
   ธีมเดิมเป็นส้มทั้งระบบ = เอาสีที่โลโก้ใช้น้อยที่สุดมาเป็นสีหลักของทั้งเว็บ

   TYPE — Tahoma แปลงจากขนาด Word: หัวข้อ 10pt→13px · เนื้อหา 9pt→12px
   เนื้อหา เมนู ตาราง ปุ่ม ใช้ขนาดเดียวกันหมด (12px) — สเกล 10/11/12/13/15/26px

   class contract เดิมไม่เปลี่ยน — app.js / login.js ใช้ได้ทันทีโดยไม่ต้องแก้ markup
   ========================================================================== */

/* ------------------------------------------------------------ design tokens */
:root {
  /* brand — จากโลโก้ */
  --brand: #071b35;
  --brand-2: #16375c;
  --brand-ink: #ffffff;

  /* primary = cyan · สัญญาณ / ข้อมูล / active */
  --primary: #00a9c7;
  --primary-strong: #00738c;          /* ตัวอักษรบนพื้นสว่าง (contrast >= 4.5:1) */
  --primary-ink: #ffffff;
  --primary-soft: rgba(0, 169, 199, .12);

  /* ปุ่มหลัก = navy · คอนทราสต์สูงพอสำหรับตัวอักษร 11px */
  --cta-1: #1c4373;
  --cta-2: #0b2545;
  --cta-ink: #ffffff;

  /* surfaces — ice / cool neutral ตามไทล์โลโก้ */
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-2: #f4f8fb;
  --surface-3: #e6eef5;
  --border: #dce6ef;
  --border-strong: #c2d2e0;
  --text: #0f2340;
  --text-dim: #5c7189;

  /* semantic */
  --accent: #00738c;
  --accent-soft: rgba(0, 169, 199, .12);
  --online: #12996b;
  --online-soft: rgba(18, 153, 107, .13);
  --danger: #d64545;
  --danger-soft: rgba(214, 69, 69, .12);
  --warn: #a86a12;
  --warn-soft: rgba(255, 167, 38, .18);
  --live: #e2660a;
  --live-soft: rgba(255, 122, 28, .14);
  --in: #16375c;
  --out: #00738c;

  /* type scale (Tahoma) — เนื้อหาหลักเท่ากันหมดที่ 9pt = 12px
     ผู้ใช้เลือก "เท่ากันหมดจริง ๆ" — ทุก token = 12px (Tahoma 9pt)
     ยกเว้น kpi 20 = ตัวเลขบนการ์ดสรุป (ลดจาก 26 ให้เข้ากับตัวอักษร 12px)
     token ยังแยกชื่อไว้ เผื่ออยากไล่ลำดับใหม่ทีหลังโดยแก้ที่นี่ที่เดียว */
  --fs-2xs: 12px;
  --fs-xs: 12px;
  --fs-sm: 12px;
  --fs-md: 12px;
  --fs-lg: 12px;
  --fs-xl: 12px;
  --fs-kpi: 20px;

  /* shape / depth */
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(7, 27, 53, .05), 0 6px 18px rgba(7, 27, 53, .06);
  --shadow-sm: 0 1px 2px rgba(7, 27, 53, .07);
  --topbar-h: 50px;

  font-family: Tahoma, Verdana, "Segoe UI", "Noto Sans Thai", Garuda, sans-serif;
  color-scheme: light;
}

/* dark — ตามค่าเครื่องผู้ใช้ (ถ้าไม่ได้บังคับ light ไว้) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #0a1a2e;
    --brand-2: #17395e;
    --brand-ink: #eaf4fa;
    --primary: #2ec7e3;
    --primary-strong: #6fdcf2;
    --primary-ink: #04202b;
    --primary-soft: rgba(46, 199, 227, .14);
    --cta-1: #2ed0ec;
    --cta-2: #0fa2be;
    --cta-ink: #04202b;
    --bg: #0a1524;
    --surface: #0f1f33;
    --surface-2: #152a42;
    --surface-3: #1b3350;
    --border: #1e3550;
    --border-strong: #2b4666;
    --text: #e8f1f8;
    --text-dim: #90a7bd;
    --accent: #6fdcf2;
    --accent-soft: rgba(46, 199, 227, .15);
    --online: #35d19a;
    --online-soft: rgba(53, 209, 154, .15);
    --danger: #ff7070;
    --danger-soft: rgba(255, 112, 112, .15);
    --warn: #e0982f;
    --warn-soft: rgba(224, 152, 47, .16);
    --live: #ff8f42;
    --live-soft: rgba(255, 143, 66, .16);
    --in: #7fb3ff;
    --out: #6fdcf2;
    --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 8px 24px rgba(0, 0, 0, .45);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

/* dark — บังคับด้วยปุ่มสลับธีม */
:root[data-theme="dark"] {
  --brand: #0a1a2e;
  --brand-2: #17395e;
  --brand-ink: #eaf4fa;
  --primary: #2ec7e3;
  --primary-strong: #6fdcf2;
  --primary-ink: #04202b;
  --primary-soft: rgba(46, 199, 227, .14);
  --cta-1: #2ed0ec;
  --cta-2: #0fa2be;
  --cta-ink: #04202b;
  --bg: #0a1524;
  --surface: #0f1f33;
  --surface-2: #152a42;
  --surface-3: #1b3350;
  --border: #1e3550;
  --border-strong: #2b4666;
  --text: #e8f1f8;
  --text-dim: #90a7bd;
  --accent: #6fdcf2;
  --accent-soft: rgba(46, 199, 227, .15);
  --online: #35d19a;
  --online-soft: rgba(53, 209, 154, .15);
  --danger: #ff7070;
  --danger-soft: rgba(255, 112, 112, .15);
  --warn: #e0982f;
  --warn-soft: rgba(224, 152, 47, .16);
  --live: #ff8f42;
  --live-soft: rgba(255, 143, 66, .16);
  --in: #7fb3ff;
  --out: #6fdcf2;
  --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 8px 24px rgba(0, 0, 0, .45);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

/* light — บังคับด้วยปุ่มสลับธีม */
:root[data-theme="light"] {
  --brand: #071b35;
  --brand-2: #16375c;
  --brand-ink: #ffffff;
  --primary: #00a9c7;
  --primary-strong: #00738c;
  --primary-ink: #ffffff;
  --primary-soft: rgba(0, 169, 199, .12);
  --cta-1: #1c4373;
  --cta-2: #0b2545;
  --cta-ink: #ffffff;
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-2: #f4f8fb;
  --surface-3: #e6eef5;
  --border: #dce6ef;
  --border-strong: #c2d2e0;
  --text: #0f2340;
  --text-dim: #5c7189;
  --accent: #00738c;
  --accent-soft: rgba(0, 169, 199, .12);
  --online: #12996b;
  --online-soft: rgba(18, 153, 107, .13);
  --danger: #d64545;
  --danger-soft: rgba(214, 69, 69, .12);
  --warn: #a86a12;
  --warn-soft: rgba(255, 167, 38, .18);
  --live: #e2660a;
  --live-soft: rgba(255, 122, 28, .14);
  --in: #16375c;
  --out: #00738c;
  --shadow: 0 1px 2px rgba(7, 27, 53, .05), 0 6px 18px rgba(7, 27, 53, .06);
  --shadow-sm: 0 1px 2px rgba(7, 27, 53, .07);
  color-scheme: light;
}

/* ------------------------------------------------------------------- base */
* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-sm);
  line-height: 1.6;                    /* ไทยต้องการที่ว่างให้สระบน/ล่าง */
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

a { color: var(--primary-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
/* ผู้ใช้ขอ: ไม่ใช้ตัวหนาทั้งระบบ — <b>/<strong> ใน markup จึงถูกกดให้เป็นน้ำหนักปกติด้วย */
b, strong { font-weight: 400; }

h1, h2, h3, h4, h5 {
  margin: 0 0 .4rem;
  font-weight: 400;
  line-height: 1.4;
  color: var(--text);
  text-wrap: balance;
}
h1 { font-size: var(--fs-xl); }
h2, h3, h4 { font-size: var(--fs-lg); }
h5 { font-size: var(--fs-sm); }
p { margin: 0 0 .5rem; }

/* ------------------------------------------------------------------ login */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(900px 520px at 15% -10%, var(--primary-soft), transparent 62%),
    radial-gradient(760px 460px at 92% 108%, rgba(22, 55, 92, .10), transparent 60%),
    var(--bg);
}

/* การ์ด login = 2 คอลัมน์ · ซ้ายแบรนด์ ขวาฟอร์ม (เดิมเป็นกล่องเดี่ยวลอยกลางจอ) */
.login-card {
  width: 100%;
  max-width: 760px;
  display: grid;
  grid-template-columns: 286px 1fr;
  align-items: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.login-card .logo {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: .4rem;
  padding: 1.7rem 1.25rem;
  text-align: left;
  background: linear-gradient(155deg, #f4fafc 0%, #e2eff5 55%, #d7e9f2 100%);
  border-right: 1px solid var(--border);
}
:root[data-theme="dark"] .login-card .logo {
  background: linear-gradient(155deg, #12263e 0%, #0e1e33 60%, #0b1728 100%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .login-card .logo {
    background: linear-gradient(155deg, #12263e 0%, #0e1e33 60%, #0b1728 100%);
  }
}
.login-card .logo img {
  width: 100%;
  max-height: 72px;
  object-fit: contain;
  object-position: left center;
  margin-bottom: .35rem;
}
.login-card .logo b {
  display: block;
  font-size: var(--fs-lg);
  font-weight: 400;
  letter-spacing: .01em;
  color: var(--text);
}
/* โลโก้มีชื่อแบรนด์อยู่ในภาพแล้ว — ไม่ต้องพิมพ์ซ้ำใต้ภาพ */
.login-card .logo:has(img[src]) b { display: none; }
.login-sub {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  line-height: 1.8;
  margin-top: .35rem;
  font-weight: 400;
}
/* ฝั่งขวา = ฟอร์ม */
.login-body { padding: 1.5rem 1.6rem 1.6rem; min-width: 0; }
.login-title {
  font-size: var(--fs-xl);
  font-weight: 400;
  margin: 0 0 .1rem;
}
.login-body > label:first-of-type { margin-top: 1.1rem; }
.login-hint {
  margin: .9rem 0 0;
  font-size: var(--fs-xs);
  color: var(--text-dim);
  line-height: 1.75;
}

.login-note {
  margin: auto 0 0;
  padding-top: .9rem;
  border-top: 1px solid color-mix(in srgb, var(--border-strong) 60%, transparent);
  font-size: var(--fs-xs);
  color: var(--text-dim);
  line-height: 1.95;
}
.login-note div { position: relative; padding-left: .85rem; }
.login-note div::before {
  content: "";
  position: absolute;
  left: 0;
  top: .68em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--primary);
}
.login-foot {
  margin-top: 1rem;
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--text-dim);
  letter-spacing: .02em;
}

@media (max-width: 640px) {
  .login-card { grid-template-columns: 1fr; }
  .login-card .logo {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 1.2rem 1.3rem;
  }
  .login-note { margin-top: .9rem; }
  .login-body { padding: 1.2rem 1.3rem 1.4rem; }
}

/* -------------------------------------------------------------- app shell */
.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem .7rem .7rem;
  gap: .15rem;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;                 /* โลโก้กว้างเต็มแถบ คำบรรยายจึงจัดกึ่งกลางให้สมมาตร */
  text-align: center;
  gap: .45rem;
  padding: .2rem .25rem 1rem;
  margin-bottom: .55rem;
  border-bottom: 1px solid var(--border);
}
/* โลโก้กว้างเต็มแถบเมนู (สัดส่วนภาพ 600×160 → สูงราว 58px) */
.brand img { width: 100%; max-height: 62px; object-fit: contain; object-position: left center; }
.brand .brand-name {
  font-size: var(--fs-lg);
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: .01em;
}
.brand-lock { display: flex; flex-direction: column; align-items: center; min-width: 0; line-height: 1.25; }
.brand-sub {
  font-size: var(--fs-xs);
  font-weight: 400;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .13em;
  margin-top: 2px;
}
/* มีโลโก้แล้วไม่ต้องพิมพ์ชื่อแบรนด์ซ้ำใต้โลโก้อีก — เหลือไว้แค่คำบรรยาย */
.brand:has(img[src]) .brand-name { display: none; }

/* ธีมมืด: คำว่า "Quantum" ในโลโก้เป็นสีกรมท่า จะจมหายไปกับพื้นมืด
   จึงวางโลโก้บนแผ่นสีเดียวกับไทล์ในตัวโลโก้ (#f4fafc) ให้กลืนเป็นชิ้นเดียวกัน */
:root[data-theme="dark"] .brand img,
:root[data-theme="dark"] .login-card .logo img {
  background: linear-gradient(160deg, #eef5f9, #e2ecf3);
  padding: 8px 11px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, .09);
  box-shadow: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand img,
  :root:not([data-theme="light"]) .login-card .logo img {
    background: linear-gradient(160deg, #eef5f9, #e2ecf3);
    padding: 8px 11px;
    border-radius: var(--radius);
    border: 1px solid rgba(255, 255, 255, .09);
    box-shadow: none;
  }
}

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .6rem;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: var(--fs-sm);          /* 12px = Tahoma 9pt — เท่ากับเนื้อหา */
  font-weight: 400;
  position: relative;
  transition: color .14s ease, background .14s ease;
}
/* เมาส์โอเวอร์ = พื้นเข้มขึ้นชัด + ตัวอักษรเข้มสุด (เดิมจางจนแทบไม่รู้ว่าชี้อยู่ตรงไหน) */
.nav a:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--brand) 10%, var(--surface));
  text-decoration: none;
}
.nav a.active {
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 400;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 26%, transparent);
}
.nav a.active::before {
  content: "";
  position: absolute;
  left: -.7rem;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 16px;
  border-radius: 0 3px 3px 0;
  background: var(--primary);
}
.nav .ic { width: 16px; height: 16px; flex-shrink: 0; stroke-width: 1.8; opacity: .9; }

/* หัวกลุ่มเมนู -- 10 รายการเรียงเรียบทำให้ทุกอันดูสำคัญเท่ากันหมด ทั้งที่
   "เครื่องในระบบ" เปิดทุกวันแต่ "ตั้งค่าระบบ" เปิดปีละครั้ง  หัวกลุ่มบอกลูกค้าว่า
   ส่วนไหนไม่ใช่ของตัวเอง ซึ่งลดความรู้สึกว่าระบบซับซ้อนได้ดีกว่าการซ่อนเมนูทิ้ง
   ★ หัวกลุ่มของโซนแอดมินต้องติด data-admin ด้วย ไม่งั้น viewer จะเห็นหัวกลุ่มลอย
     โดยไม่มีเมนูอยู่ใต้มัน (app.js ซ่อนทุก [data-admin] ให้เองอยู่แล้ว) */
.navgrp {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  opacity: .75;
  letter-spacing: .05em;
  padding: .1rem .6rem;
  margin-top: .7rem;
}
.navgrp:first-child { margin-top: 0; }

.sidebar .spacer { flex: 1; }
.sidebar .foot {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  padding: .65rem .45rem 0;
  border-top: 1px solid var(--border);
  margin-top: .5rem;
}
.foot-user { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.foot-user b { font-weight: 400; font-size: var(--fs-sm); color: var(--text); }
.foot-user .avatar {
  width: 24px;
  height: 24px;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
}

/* ------------------------------------------------------------ main column */
.main {
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 1.15rem 1.6rem;
  min-width: 0;
}

/* จอกว้างมาก (2K/4K) — จำกัดความกว้างเนื้อหา ไม่งั้นตารางยืดเต็ม 2560px
   จนสายตาไล่จากคอลัมน์ซ้ายไปขวาไม่ทัน */
.main > .topbar,
.main > #view {
  width: 100%;
  max-width: 1680px;
  margin-inline: auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .5rem 0;
  margin-bottom: .85rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: var(--fs-xl); font-weight: 400; }
.crumb {
  font-size: var(--fs-2xs);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .11em;
  margin-bottom: .1rem;
}
.topbar .who {
  color: var(--text-dim);
  font-size: var(--fs-sm);
  display: flex;
  align-items: center;
  gap: .55rem;
}
.pill {
  font-size: var(--fs-2xs);
  font-weight: 400;
  padding: .16rem .5rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  letter-spacing: .06em;
  text-transform: uppercase;
}
.pill.admin {
  background: var(--primary-soft);
  color: var(--primary-strong);
  border-color: color-mix(in srgb, var(--primary) 28%, transparent);
}
.avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(160deg, var(--cta-1), var(--cta-2));
  color: var(--cta-ink);
  display: grid;
  place-items: center;
  font-weight: 400;
  font-size: var(--fs-xs);
  flex: 0 0 auto;
}

/* ------------------------------------------------------------ cards / grid */
.grid { display: grid; gap: .7rem; }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cols-5 { grid-template-columns: repeat(5, 1fr); }
/* 5 ใบเรียงกันเริ่มบีบจนกราฟจิ๋วต่ำกว่า ~1500px จึงลดเป็น 3 ก่อนถึงกฎจอเล็ก */
@media (max-width: 1500px) { .cols-5 { grid-template-columns: repeat(3, 1fr); } }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-2 { grid-template-columns: repeat(2, 1fr); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: .75rem .9rem;
}
.card h3 { font-size: var(--fs-lg); font-weight: 400; margin: 0 0 .15rem; }

/* KPI */
.card.stat { display: flex; flex-direction: column; padding: .55rem .75rem .6rem; }
.stat .stat-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.stat .label {
  color: var(--text-dim);
  font-size: var(--fs-xs);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: .07em;
  line-height: 1.4;
}
.stat .value {
  font-size: var(--fs-kpi);
  font-weight: 400;
  margin-top: .15rem;
  line-height: 1.15;
  letter-spacing: -.015em;
  color: var(--text);
}
.stat .sub { color: var(--text-dim); font-size: var(--fs-xs); margin-top: auto; padding-top: .35rem; line-height: 1.5; }
.stat .chip {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary-strong);
}
.stat .chip svg { width: 12px; height: 12px; stroke-width: 1.9; }
.stat.online .chip { background: var(--live-soft); color: var(--live); }
.stat.online .value { color: var(--live); }

.statuschip {
  display: inline-flex;
  align-items: center;
  gap: .32rem;
  font-size: var(--fs-xs);
  font-weight: 400;
  padding: .1rem .45rem;
  border-radius: 999px;
  background: var(--live-soft);
  color: var(--live);
}
.statuschip .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  position: relative;
  flex: 0 0 auto;
}
.statuschip .dot::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  opacity: .6;
  animation: rdwm-pulse 1.6s ease-out infinite;
}

.miniprog { height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.miniprog i {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--primary), color-mix(in srgb, var(--primary) 55%, transparent));
}

/* ------------------------------------------------------------------ chart */
.chartcard { display: flex; flex-direction: column; }
.chartcard .plot { flex: 1; min-height: 168px; }
.plot { position: relative; height: 168px; margin-top: .9rem; padding-left: 26px; }
.yaxis { position: absolute; left: 0; top: 0; bottom: 18px; width: 26px; }
.yaxis span {
  position: absolute;
  right: 6px;
  transform: translateY(-50%);
  font-size: var(--fs-2xs);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.grid-lines { position: absolute; left: 26px; right: 0; top: 0; bottom: 18px; }
.grid-lines i { position: absolute; left: 0; right: 0; height: 1px; background: var(--border); }
.bars {
  position: absolute;
  left: 26px;
  right: 0;
  top: 0;
  bottom: 18px;
  display: flex;
  align-items: flex-end;
  gap: 3px;
}
.bars .col { flex: 1; height: 100%; display: flex; align-items: flex-end; position: relative; }
.bars .bar {
  width: 100%;
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: filter .14s ease;
  background: linear-gradient(180deg, var(--primary), color-mix(in srgb, var(--primary) 42%, transparent));
  transform-origin: bottom center;
  animation: rdwm-bar-in .45s cubic-bezier(.22, 1, .36, 1) both;
}
.bars .bar.zero { background: var(--surface-3); }
.bars .bar.peak { background: linear-gradient(180deg, var(--cta-1), var(--brand)); }
:root[data-theme="dark"] .bars .bar.peak {
  background: linear-gradient(180deg, var(--primary-strong), var(--primary));
}
.bars .col:hover .bar:not(.zero) { filter: brightness(1.08) saturate(1.08); }
.bars .col .tip {
  position: absolute;
  bottom: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--brand);
  color: var(--brand-ink);
  font-size: var(--fs-xs);
  font-weight: 400;
  padding: .12rem .4rem;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s;
  z-index: 2;
}
.bars .col:hover .tip { opacity: 1; }
.xaxis { position: absolute; left: 26px; right: 0; bottom: 0; display: flex; gap: 3px; }
.xaxis div { flex: 1; text-align: center; font-size: var(--fs-2xs); color: var(--text-dim); }

/* sparkline บนการ์ด KPI */
.spark { display: block; width: 100%; height: 20px; overflow: visible; }
.spark-empty { height: 20px; }
.spark-area { fill: var(--primary-soft); stroke: none; }
.spark-line {
  fill: none;
  stroke: var(--primary);
  stroke-width: 1.4;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;   /* เส้นหนาเท่ากันแม้ viewBox ถูกยืด */
}
.spark-dot { fill: var(--primary); stroke: var(--surface); stroke-width: .8; vector-effect: non-scaling-stroke; }
.sparkcap { margin-top: .2rem; color: var(--text-dim); }

/* -------------------------------------------------------------- side facts */
.sidecard { display: flex; flex-direction: column; }
.facts { list-style: none; padding: 0; margin: .6rem 0 0; }
.facts li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .8rem;
  padding: .4rem 0;
  border-bottom: 1px solid var(--border);
}
.facts li:last-child { border-bottom: 0; }
.facts .k { color: var(--text-dim); font-size: var(--fs-sm); }
.facts .v {
  font-weight: 400;
  font-size: var(--fs-md);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.facts .v small {
  display: block;
  font-weight: 400;
  font-size: var(--fs-xs);
  color: var(--text-dim);
  margin-top: .05rem;
}
.cardnote {
  margin: auto 0 0;
  padding-top: .8rem;
  font-size: var(--fs-xs);
  line-height: 1.8;
  color: var(--text-dim);
}

/* ----------------------------------------------------------- empty states */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: 1.4rem 0;
  color: var(--text-dim);
  text-align: center;
}
.empty svg { width: 22px; height: 22px; stroke-width: 1.6; opacity: .45; }
.empty span { font-size: var(--fs-sm); }

/* ----------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; margin: 0 -.15rem; }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
th, td {
  text-align: left;
  padding: .34rem .55rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
/* NOTE: หัวตารางไม่ทำ sticky — .table-wrap มี overflow-x จึงเป็น scroll container
   ของตัวเอง sticky จะถูกดันลงมาทับแถวแรกแทนที่จะเกาะขอบบนจอ */
th {
  background: var(--surface);
  color: var(--text-dim);
  font-weight: 400;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1px solid var(--border-strong);
}
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: color-mix(in srgb, var(--brand) 7%, var(--surface)); }
tbody tr:last-child td { border-bottom: 0; }
tr.row-off td { opacity: .5; }

/* ตารางคอลัมน์ตายตัว -- ใช้กับตารางที่มีช่องข้อความยาวไม่จำกัด (audit)
   ปกติ table เป็น auto layout คือกางคอลัมน์ตามเนื้อหา  พอ th/td เป็น nowrap
   ทั้งแผง แถวเดียวที่ยาว ~200 ตัวอักษรก็ดันตารางกว้างเกินการ์ด จนคอลัมน์
   ขวาสุด (IP) ถูกดันหลุดออกไปนอกกรอบ  จึงล็อกความกว้างคอลัมน์ไว้แน่นอน
   แล้วให้เฉพาะช่องที่ยาวตัดบรรทัดลงมาแทนที่จะดันตารางออกข้าง */
table.fixed { table-layout: fixed; min-width: 760px; }
table.fixed td.wrap {
  white-space: normal;
  /* anywhere ไม่ใช่ break-word -- บางรายการเป็นชื่อไฟล์ยาวคำเดียวไม่มีช่องว่าง
     break-word จะไม่ลดความกว้างขั้นต่ำของคอลัมน์ให้ */
  overflow-wrap: anywhere;
  line-height: 1.55;
  padding-block: .3rem;
}

/* คอลัมน์ปุ่มท้ายแถว — ชิดขวา ไม่ปล่อยให้ลอยกลางความกว้างจอ */
td:last-child:has(.btn) { text-align: right; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: .28rem;
  font-size: var(--fs-xs);
  padding: .1rem .42rem;
  border-radius: 4px;
  font-weight: 400;
  letter-spacing: .02em;
  border: 1px solid transparent;
}
/* 3 กลุ่มเครื่อง — แยกสีให้ชัด (เดิมเป็นส้มเหมือนกันหมด แยกไม่ออก) */
.tag.user {
  background: var(--surface-3);
  color: var(--text-dim);
  border-color: var(--border-strong);
}
.tag.workstation {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 26%, transparent);
}
.tag.admin {
  background: color-mix(in srgb, var(--brand-2) 12%, transparent);
  color: var(--brand-2);
  border-color: color-mix(in srgb, var(--brand-2) 26%, transparent);
}
:root[data-theme="dark"] .tag.admin { color: #9dc4ec; }
/* ช่องทางเชื่อมต่อ */
.tag.relay {
  background: var(--primary-soft);
  color: var(--primary-strong);
  border-color: color-mix(in srgb, var(--primary) 26%, transparent);
}
.tag.direct {
  background: var(--surface-3);
  color: var(--text-dim);
  border-color: var(--border-strong);
}
/* กำลังใช้งาน = ส้มโลโก้ (ที่เดียวในระบบที่ใช้สีส้ม) */
.tag.live {
  background: var(--live-soft);
  color: var(--live);
  border-color: color-mix(in srgb, var(--live) 30%, transparent);
}
.tag.live::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

/* จุดสถานะ + ลูกศรทิศทางในตาราง session */
td.st-cell { width: 1px; padding-right: .15rem; }
.st { display: inline-flex; }
.st .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; position: relative; }
.st.done { color: var(--text-dim); opacity: .45; }
.st.on { color: var(--live); }
.st.on .dot::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  opacity: .6;
  animation: rdwm-pulse 1.6s ease-out infinite;
}
td.arrow-cell { color: var(--text-dim); text-align: center; padding: 0 .1rem; width: 1px; }

/* ---------------------------------------------------------- forms/buttons */
input, select, textarea, button { font: inherit; }
input, select, textarea {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: .4rem .55rem;
  width: 100%;
  font-size: var(--fs-sm);
  transition: border-color .14s ease, box-shadow .14s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea {
  min-height: 110px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: var(--fs-sm);
  line-height: 1.6;
}
label {
  display: block;
  font-size: var(--fs-xs);
  color: var(--text-dim);
  font-weight: 400;
  letter-spacing: .02em;
  margin: .7rem 0 .25rem;
}
input[type="checkbox"] { width: auto; accent-color: var(--primary); }
input[type="file"] { padding: .3rem .4rem; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: .4rem .75rem;
  font-size: var(--fs-sm);
  font-weight: 400;
  white-space: nowrap;
  transition: border-color .14s ease, background .14s ease, color .14s ease;
}
.btn:hover { border-color: var(--primary); color: var(--primary-strong); text-decoration: none; }

.btn.primary {
  background: linear-gradient(180deg, var(--cta-1), var(--cta-2));
  color: var(--cta-ink);
  border-color: transparent;
  font-weight: 400;
  box-shadow: 0 1px 2px rgba(7, 27, 53, .2);
}
.btn.primary:hover { filter: brightness(1.12); color: var(--cta-ink); }

/* ปุ่มลบ — โครงร่างแดง ไม่ใช่แดงทึบทั้งคอลัมน์แบบเดิม */
.btn.danger {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 38%, transparent);
}
.btn.danger:hover { background: var(--danger); color: #fff; border-color: transparent; }

.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: .22rem .5rem; font-size: var(--fs-xs); }

/* ปุ่มในตาราง (รีโมท/แก้ไข) — เบาลง ไม่ให้กลายเป็นกำแพงสีทั้งคอลัมน์ */
td .btn.sm.primary {
  background: transparent;
  color: var(--primary-strong);
  border: 1px solid color-mix(in srgb, var(--primary) 40%, transparent);
  box-shadow: none;
}
td .btn.sm.primary:hover {
  background: linear-gradient(180deg, var(--cta-1), var(--cta-2));
  color: var(--cta-ink);
  border-color: transparent;
  filter: none;
}

/* คอลัมน์ปุ่มท้ายแถวของตารางเครื่อง — รีโมท · แก้ไข · ลบ เรียงตามความถี่ที่กด
   ปุ่มลบอยู่ท้ายสุดให้ห่างจากปุ่มที่กดบ่อยที่สุด */
.rowact { white-space: nowrap; text-align: right; }
.rowact > * + * { margin-left: .3rem; }
/* เครื่องที่ยังไม่มี Q-Connect ID — คงปุ่มไว้ให้คอลัมน์ไม่กระโดด แต่กดไม่ได้
   (บอกด้วย title ว่าทำไม ไม่ใช่แค่จางแล้วปล่อยให้เดาเอง) */
.btn.off {
  background: var(--surface-3);
  color: var(--text-dim);
  border-color: var(--border);
  cursor: not-allowed;
}

.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.row > div { flex: 1; min-width: 130px; }
.row label { margin-top: 0; }
.toolbar {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: .8rem;
}
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .7rem;
  gap: 1rem;
  flex-wrap: wrap;
}

/* หน้าตั้งค่าระบบ */
.setfield { margin-bottom: .8rem; }
.setfield label { margin-top: 0; }
.sethelp { display: block; margin-top: .25rem; color: var(--text-dim); line-height: 1.6; }
.switchrow {
  display: flex;
  align-items: flex-start;
  gap: .55rem;
  margin: 0 0 .8rem;
  padding: .5rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  font-weight: 400;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  font-size: var(--fs-sm);
}
.switchrow input { margin-top: .15rem; flex: 0 0 auto; }
.switchrow b { display: block; }
.switchrow small { display: block; margin-top: .2rem; color: var(--text-dim); line-height: 1.6; }

/* หน้าเกี่ยวกับระบบ */
.aboutcard { text-align: center; padding: 1.4rem 1.2rem 1.2rem; }
.about-logo { max-width: 260px; max-height: 62px; object-fit: contain; margin-bottom: .5rem; }
.about-name { font-size: var(--fs-lg); margin: 0 0 .2rem; }
.about-tag { color: var(--primary-strong); margin: 0 0 .6rem; }
.about-lead { max-width: 62ch; margin: 0 auto; color: var(--text-dim); line-height: 1.85; }
.about-lic { color: var(--text-dim); line-height: 1.85; margin: 0 0 .5rem; }
.featlist { list-style: none; padding: 0; margin: .7rem 0 0; display: grid;
  grid-template-columns: repeat(3, 1fr); gap: .7rem; }
.feat { display: flex; gap: .6rem; align-items: flex-start;
  padding: .65rem .7rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); }
.feat-ic { flex: 0 0 auto; font-size: var(--fs-lg); line-height: 1.4; }
.feat b { display: block; margin-bottom: .15rem; }
.feat small { display: block; color: var(--text-dim); line-height: 1.7; }
@media (max-width: 1200px) { .featlist { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 860px)  { .featlist { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------------- misc */
.msg {
  padding: .5rem .7rem;
  border-radius: var(--radius-sm);
  margin: .5rem 0;
  font-size: var(--fs-sm);
  font-weight: 400;
  border: 1px solid transparent;
}
.msg.err {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}
.msg.ok {
  background: var(--online-soft);
  color: var(--online);
  border-color: color-mix(in srgb, var(--online) 30%, transparent);
}
.muted { color: var(--text-dim); }
.mono {
  font-family: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  font-size: var(--fs-xs);
  letter-spacing: -.01em;
}
.pager {
  display: flex;
  gap: .45rem;
  align-items: center;
  justify-content: flex-end;
  margin-top: .8rem;
  color: var(--text-dim);
  font-size: var(--fs-xs);
}

.hlist { list-style: none; padding: 0; margin: 0; }
.hlist li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: .4rem 0;
  border-bottom: 1px solid var(--border);
}
.hlist li:last-child { border-bottom: 0; }
.hlist li b {
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-md);
}
.hlist li > span { min-width: 0; }
/* การ์ดอันดับหน้าภาพรวม — สองใบสูงเท่ากัน จำนวนแถวคงที่ ส่วนที่เกินใช้แบ่งหน้า ไม่ใช่สกรอลบาร์ */
.card.toprank { display: flex; flex-direction: column; }
.card.toprank > div { flex: 1; display: flex; flex-direction: column; }
.hlist.toplist { flex: 1; }
.hlist li.pad { visibility: hidden; }          /* แถวเปล่ากันความสูง */
.card.toprank .pager { margin-top: auto; padding-top: .55rem; }
.card.toprank .cardnote { padding-top: .65rem; }

.bar-inline {
  height: 4px;
  border-radius: 2px;
  margin-top: .3rem;
  background: linear-gradient(90deg, var(--primary), color-mix(in srgb, var(--primary) 45%, transparent));
}

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(7, 27, 53, .55);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 1rem;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem 1.25rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 18px 50px rgba(7, 27, 53, .28);
}
.iconbtn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: var(--fs-lg);
  padding: .15rem .4rem;
  border-radius: 4px;
  line-height: 1;
}
.iconbtn:hover { background: var(--surface-2); color: var(--text); }

/* details/summary (หน้าคู่มือ) */
details.card { padding: .65rem .9rem; }
details.card + details.card { margin-top: .55rem; }
details.card > summary {
  cursor: pointer;
  font-weight: 400;
  font-size: var(--fs-lg);
  padding: .1rem 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: .45rem;
  color: var(--text);
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid var(--primary);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform .15s ease;
  flex: 0 0 auto;
}
details.card[open] > summary::before { transform: rotate(90deg); }
details.card[open] > summary { margin-bottom: .5rem; }

/* แท่งกราฟไล่ขึ้นทีละแท่งตอนเปิดหน้า (หน่วงต่อแท่งกำหนดใน app.js) */
@keyframes rdwm-bar-in {
  from { transform: scaleY(0); }
  to   { transform: scaleY(1); }
}

@keyframes rdwm-pulse {
  0% { transform: scale(.5); opacity: .7; }
  100% { transform: scale(1.9); opacity: 0; }
}

*:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ------------------------------------------------------------- responsive */
@media (max-width: 1200px) {
  .cols-4, .cols-5 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; height: auto; }
  .sidebar {
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    align-items: center;
    gap: .4rem;
    padding: .5rem .7rem;
  }
  .sidebar .spacer, .sidebar .foot { display: none; }
  .nav { flex-direction: row; }
  /* จอเล็ก เมนูกลายเป็นแถบนอนเลื่อนซ้ายขวา หัวกลุ่มจะแทรกอยู่กลางแถวอ่านไม่รู้เรื่อง */
  .navgrp { display: none; }
  .nav a.active::before { display: none; }
  .brand { padding: .2rem .4rem; border: 0; margin: 0; }
  .main { height: auto; overflow: visible; padding: 0 .9rem 1.4rem; }
  .topbar { position: static; }
  /* หัวตารางเป็น static อยู่แล้ว */
  .cols-4, .cols-5 { grid-template-columns: repeat(2, 1fr); }
  .cols-3, .cols-2 { grid-template-columns: 1fr; }
  .grid > [style*="grid-column"] { grid-column: auto !important; }
}
