/* style.css — หน้าตาของโปรแกรม (Role B) — Minimal Luxury (DECISIONS D-016)
 *
 * แนวคิด: "นิ่ง แต่โดดเด่น" — สีน้อย พื้นผิวสวย ใช้ระยะห่างและเงานุ่มแยกชั้นของหน้าจอ
 * ชั้นจากหลังไปหน้า: 1) พื้นหลัง  2) แถบ CPU ด้านซ้าย / พื้นผิวผลลัพธ์ (.surface)  3) การ์ด  4) popup
 * แถบซ้าย = รายการ CPU ที่กดแล้วการตั้งค่ากางลงมาเป็น dropdown / ตรงกลาง = ผลลัพธ์อย่างเดียว (D-017)
 *
 * โครงไฟล์:
 *   1) Design tokens: ธีมสว่าง "Cream" และธีมมืด "Ink"
 *   2) พื้นฐาน (ตัวอักษร, ไอคอน, ปุ่ม, ช่องกรอก)
 *   3) พื้นหลัง และโครงหน้า (แถบ CPU + dropdown ตั้งค่า, ส่วนหัว, พื้นผิวผลลัพธ์)
 *   4) การ์ดเนื้อหา (โปรเซส, ผลลัพธ์, Gantt, ค่าสรุป, ตาราง, สูตร, เปรียบเทียบ)
 *   5) popup และกล่องลอย
 *   6) Animation, Responsive, การลดการเคลื่อนไหว
 *
 * ทุก component ใช้สีจากตัวแปร (--ชื่อ) เท่านั้น เปลี่ยนธีมได้โดยเปลี่ยนชุดตัวแปรชุดเดียว
 */

/* ---------- 1) Design tokens: ธีมสว่าง "Cream" (ค่าเริ่มต้น) ---------- */
:root {
  /* พื้นผิว เรียงจากชั้นล่างไปบน */
  --bg-base: #ece6de;                        /* พื้นหลังครีมอมเทา (D-030: ลดความจ้า) */
  --bg-surface: rgba(247, 243, 237, 0.62);   /* พื้นผิวหลักของแอป */
  --bg-card: #faf7f2;                        /* การ์ด (ขาวนวลอมครีม ไม่แสบตา) */
  --bg-inset: #f1ebe3;                       /* ช่องด้านในการ์ด (เบจอ่อน) */
  --surface-hover: #ebe2d7;
  --input-bg: #fdfbf7;
  --track-bg: #e9e0d5;

  /* แถบเมนูซ้าย: สีอ่อนแบบกระจกฝ้า กลืนกับพื้นครีม (D-031 — เดิมเป็นน้ำเงินเข้ม ตัดกับพื้นแรงเกินไป)
     ธีมมืดยังเป็นแถบเข้มเหมือนเดิม (ค่าในบล็อกธีมมืด) */
  --bg-sidebar: #f4efe8;
  --sidebar-surface: #f8f4ee;                /* การ์ด CPU ที่ไม่ได้เลือก: ขาวนวลลอยบนแถบ (หม่นกว่าตัวที่เลือกเล็กน้อย) */
  --sidebar-hover: #ece4da;
  --sidebar-border: rgba(42, 44, 63, 0.09);
  --sidebar-text: #2a2c3f;
  --sidebar-muted: #67637a;
  --sidebar-line: rgba(42, 44, 63, 0.2);     /* เส้นประปุ่ม "เพิ่ม CPU" */
  --sidebar-line-hover: rgba(42, 44, 63, 0.34);
  --sidebar-ghost: rgba(42, 44, 63, 0.03);   /* พื้นจาง ๆ ของปุ่มลูกศร */
  --sidebar-ghost-hover: rgba(42, 44, 63, 0.07);
  --sidebar-sheen: rgba(255, 255, 255, 0.7); /* เส้นแสงขอบบนของแถบและการ์ด */
  --sidebar-card-shadow: 0 1px 2px rgba(60, 44, 40, 0.06), 0 10px 20px -14px rgba(60, 44, 40, 0.28);
  --sidebar-card-shadow-hover: 0 2px 4px rgba(60, 44, 40, 0.08), 0 18px 30px -16px rgba(60, 44, 40, 0.34);
  --sidebar-active-shadow: 0 2px 6px rgba(60, 44, 40, 0.08), 0 22px 40px -18px rgba(60, 44, 40, 0.32);
  --cpu-active-bg: #fffcf8;                  /* CPU ที่เลือก = การ์ดสีขาวนวลลอยเด่นที่สุดในแถบ */
  --cpu-active-ring: 1.5px;                  /* + เส้นขอบสีประจำ CPU (การ์ดทุกใบสีอ่อนเหมือนกัน ต้องมีขอบช่วยแยก) */
  --cpu-active-text: #22253a;
  --cpu-active-muted: #625e72;

  /* ป้ายสถานะบนการ์ด CPU (D-034) ตัวอักษรบนพื้นสีจางของตัวเอง contrast ≥ 5:1 บนการ์ดทั้งสองแบบ */
  --status-done-text: #1b6b45;
  --status-done-tint: #2f9e68;
  --status-stale-text: #835410;
  --status-stale-tint: #d49628;
  --status-idle-text: #5c5870;
  --status-idle-line: rgba(42, 44, 63, 0.3);

  /* ตัวอักษร (น้ำเงินหมึก ไม่ใช่ดำสนิท) */
  --text-primary: #2a2c3f;
  --text-secondary: #4d4e66;
  --text-muted: #67637a;

  --border-soft: rgba(34, 37, 58, 0.07);
  --border: rgba(34, 37, 58, 0.13);
  --border-strong: rgba(34, 37, 58, 0.22);

  /* สีเน้น: คอรัล (หลัก) / ลาเวนเดอร์หม่น / ทองแชมเปญ / ชมพูหม่น */
  --accent: #d9664f;
  --accent-text: #ad4733;                    /* คอรัลเข้มพอให้อ่านบนพื้นอ่อน */
  --accent-soft: #fbe5dc;
  --accent-lavender: #8278c4;
  --accent-gold: #bf9454;
  --accent-rose: #c96a82;
  --button-from: #bd4f39;                    /* ปุ่มหลักใช้ตัวอักษรขาว จึงต้องเข้มพอ (contrast ≥ 4.5:1) */
  --button-to: #b0476b;
  --focus-color: #c9573f;

  --color-success: #266f4f;
  --color-warning: #8f610b;
  --color-error: #b3364d;
  --success-soft: #e2f1e9;
  --warning-soft: #fbefd8;
  --error-soft: #fbe4e7;
  --badge-text: #ffffff;
  --process-text: #1d1f2f;                   /* ตัวอักษรบนแถบสีโปรเซส ใช้ค่าเดียวทั้งสองธีม เพราะสีแถบไม่เปลี่ยนตามธีม (D-045) */


  /* สีประจำ CPU ในแถบซ้าย วนตามลำดับ */
  --cpu-accent-0: #d9664f;
  --cpu-accent-1: #8278c4;
  --cpu-accent-2: #bf9454;
  --cpu-accent-3: #c96a82;

  /* เงานุ่ม 4 ระดับ ยิ่งลอยสูง เงายิ่งกว้างและจาง */
  --shadow-xs: 0 1px 2px rgba(48, 36, 44, 0.06);
  --shadow-sm: 0 1px 2px rgba(48, 36, 44, 0.05), 0 4px 12px -4px rgba(48, 36, 44, 0.1);
  --shadow-md: 0 1px 2px rgba(48, 36, 44, 0.04), 0 12px 30px -14px rgba(72, 44, 52, 0.2);
  --shadow-lg: 0 2px 6px rgba(48, 36, 44, 0.04), 0 30px 70px -30px rgba(72, 44, 52, 0.26);
  --shadow-popup: 0 4px 10px rgba(30, 24, 40, 0.06), 0 40px 90px -24px rgba(30, 24, 40, 0.45);
  --shadow-button: 0 10px 22px -10px rgba(185, 72, 72, 0.6);

  /* พื้นหลัง */
  --glow-1: rgba(214, 198, 238, 0.36);       /* ลาเวนเดอร์จาง มุมขวาบน */
  --glow-2: rgba(240, 205, 184, 0.4);        /* พีชจาง มุมซ้ายล่าง */
  --sun-from: rgba(240, 196, 166, 0.8);
  --sun-to: rgba(226, 168, 178, 0.38);
  --sun-opacity: 0.42;
  --ember: rgba(236, 168, 128, 0.4);          /* แสงส้ม ambient ที่ขยาย/หดในพื้นหลัง */
  --art-color: #7a5fa8;                      /* เส้นภาพชิป CPU พื้นหลัง (จางด้วย --art-opacity) */
  --art-opacity: 0.12;
  --panel-sidebar: rgba(246, 242, 236, 0.72); /* แถบซ้ายสีอ่อนโปร่ง 28% + เบลอ (D-031) */
  --figure-from: #fdf1ea;                    /* พื้นภาพประกอบใน popup */
  --figure-to: #f1ecf8;
  --title-gradient: linear-gradient(100deg, #262a4f 0%, #6e4f8f 34%, #c9573f 70%, #d9965a 100%);

  color-scheme: light;
}

/* ธีมมืด "Ink" ใช้ได้ 2 ทาง:
   1) ผู้ใช้ไม่ได้กดปุ่มสลับ และเครื่องตั้งเป็นโหมดมืด (@media)
   2) ผู้ใช้กดปุ่มสลับเป็นโหมดมืด (theme.js ใส่ data-theme="dark" ที่ <html>)
   CSS รวมสองกรณีไว้ใน selector เดียวไม่ได้ จึงต้องเขียนชุดสีซ้ำสองที่ ถ้าแก้สีให้แก้ทั้งสองที่ */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-base: #121320;
    --bg-surface: rgba(25, 27, 41, 0.62);
    --bg-card: #1d1f2f;
    --bg-inset: #171928;
    --surface-hover: #262941;
    --input-bg: #141626;
    --track-bg: #2a2d44;

    --bg-sidebar: #0d0e18;
    --sidebar-surface: #1b1d2d;
    --sidebar-hover: #24273b;
    --sidebar-border: rgba(255, 255, 255, 0.07);
    --sidebar-text: #f1ecf2;
    --sidebar-muted: #a19db5;
    --sidebar-line: rgba(255, 255, 255, 0.2);
    --sidebar-line-hover: rgba(255, 255, 255, 0.35);
    --sidebar-ghost: rgba(255, 255, 255, 0.04);
    --sidebar-ghost-hover: rgba(255, 255, 255, 0.1);
    --sidebar-sheen: rgba(255, 255, 255, 0.07);
    --sidebar-card-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 20px -14px rgba(0, 0, 0, 0.7);
    --sidebar-card-shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.3), 0 18px 30px -16px rgba(0, 0, 0, 0.8);
    --sidebar-active-shadow: 0 2px 6px rgba(0, 0, 0, 0.18), 0 22px 40px -18px rgba(0, 0, 0, 0.75);
    --cpu-active-bg: #2d3049;
    --cpu-active-ring: 0px;
    --cpu-active-text: #f6f1ec;
    --cpu-active-muted: #c4bfd3;

    --status-done-text: #86e3b6;
    --status-done-tint: #5fc898;
    --status-stale-text: #f1c97f;
    --status-stale-tint: #e3b25e;
    --status-idle-text: #b3aec6;
    --status-idle-line: rgba(255, 255, 255, 0.24);

    --text-primary: #f2ede7;
    --text-secondary: #c4bfce;
    --text-muted: #a09bae;

    --border-soft: rgba(255, 255, 255, 0.06);
    --border: rgba(255, 255, 255, 0.11);
    --border-strong: rgba(255, 255, 255, 0.2);

    --accent: #ee8a73;
    --accent-text: #f29d88;
    --accent-soft: rgba(238, 138, 115, 0.14);
    --accent-lavender: #a99ee6;
    --accent-gold: #d8b47a;
    --accent-rose: #e392a8;
    --button-from: #cf6249;
    --button-to: #b1507a;
    --focus-color: #f29d88;

    --color-success: #66d3a0;
    --color-warning: #e9bc62;
    --color-error: #f1869b;
    --success-soft: rgba(102, 211, 160, 0.12);
    --warning-soft: rgba(233, 188, 98, 0.11);
    --error-soft: rgba(241, 134, 155, 0.13);
    --badge-text: #0f2a1d;


    --cpu-accent-0: #e07a62;
    --cpu-accent-1: #8f85d6;
    --cpu-accent-2: #c9a066;
    --cpu-accent-3: #d27d95;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 14px -6px rgba(0, 0, 0, 0.45);
    --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 34px -16px rgba(0, 0, 0, 0.65);
    --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.3), 0 34px 80px -30px rgba(0, 0, 0, 0.8);
    --shadow-popup: 0 4px 12px rgba(0, 0, 0, 0.35), 0 44px 100px -24px rgba(0, 0, 0, 0.85);
    --shadow-button: 0 10px 24px -10px rgba(207, 98, 73, 0.6);

    --glow-1: rgba(110, 92, 170, 0.28);
    --glow-2: rgba(170, 90, 90, 0.2);
    --sun-from: rgba(228, 143, 120, 0.75);
    --sun-to: rgba(150, 82, 130, 0.35);
    --sun-opacity: 0.32;
    --ember: rgba(236, 122, 78, 0.45);
    --art-color: #b7a2ff;
    --art-opacity: 0.11;
    --panel-sidebar: rgba(13, 14, 24, 0.72);
    --figure-from: #262236;
    --figure-to: #1e2236;
    --title-gradient: linear-gradient(100deg, #f4ebe3 0%, #c9b8ec 34%, #ee8a73 70%, #f0c48a 100%);

    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg-base: #121320;
  --bg-surface: rgba(25, 27, 41, 0.62);
  --bg-card: #1d1f2f;
  --bg-inset: #171928;
  --surface-hover: #262941;
  --input-bg: #141626;
  --track-bg: #2a2d44;

  --bg-sidebar: #0d0e18;
  --sidebar-surface: #1b1d2d;
  --sidebar-hover: #24273b;
  --sidebar-border: rgba(255, 255, 255, 0.07);
  --sidebar-text: #f1ecf2;
  --sidebar-muted: #a19db5;
  --sidebar-line: rgba(255, 255, 255, 0.2);
  --sidebar-line-hover: rgba(255, 255, 255, 0.35);
  --sidebar-ghost: rgba(255, 255, 255, 0.04);
  --sidebar-ghost-hover: rgba(255, 255, 255, 0.1);
  --sidebar-sheen: rgba(255, 255, 255, 0.07);
  --sidebar-card-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 20px -14px rgba(0, 0, 0, 0.7);
  --sidebar-card-shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.3), 0 18px 30px -16px rgba(0, 0, 0, 0.8);
  --sidebar-active-shadow: 0 2px 6px rgba(0, 0, 0, 0.18), 0 22px 40px -18px rgba(0, 0, 0, 0.75);
  --cpu-active-bg: #2d3049;
  --cpu-active-ring: 0px;
  --cpu-active-text: #f6f1ec;
  --cpu-active-muted: #c4bfd3;

  --status-done-text: #86e3b6;
  --status-done-tint: #5fc898;
  --status-stale-text: #f1c97f;
  --status-stale-tint: #e3b25e;
  --status-idle-text: #b3aec6;
  --status-idle-line: rgba(255, 255, 255, 0.24);

  --text-primary: #f2ede7;
  --text-secondary: #c4bfce;
  --text-muted: #a09bae;

  --border-soft: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.11);
  --border-strong: rgba(255, 255, 255, 0.2);

  --accent: #ee8a73;
  --accent-text: #f29d88;
  --accent-soft: rgba(238, 138, 115, 0.14);
  --accent-lavender: #a99ee6;
  --accent-gold: #d8b47a;
  --accent-rose: #e392a8;
  --button-from: #cf6249;
  --button-to: #b1507a;
  --focus-color: #f29d88;

  --color-success: #66d3a0;
  --color-warning: #e9bc62;
  --color-error: #f1869b;
  --success-soft: rgba(102, 211, 160, 0.12);
  --warning-soft: rgba(233, 188, 98, 0.11);
  --error-soft: rgba(241, 134, 155, 0.13);
  --badge-text: #0f2a1d;


  --cpu-accent-0: #e07a62;
  --cpu-accent-1: #8f85d6;
  --cpu-accent-2: #c9a066;
  --cpu-accent-3: #d27d95;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 14px -6px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 34px -16px rgba(0, 0, 0, 0.65);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.3), 0 34px 80px -30px rgba(0, 0, 0, 0.8);
  --shadow-popup: 0 4px 12px rgba(0, 0, 0, 0.35), 0 44px 100px -24px rgba(0, 0, 0, 0.85);
  --shadow-button: 0 10px 24px -10px rgba(207, 98, 73, 0.6);

  --glow-1: rgba(110, 92, 170, 0.28);
  --glow-2: rgba(170, 90, 90, 0.2);
  --sun-from: rgba(228, 143, 120, 0.75);
  --sun-to: rgba(150, 82, 130, 0.35);
  --sun-opacity: 0.32;
  --ember: rgba(236, 122, 78, 0.45);
  --art-color: #b7a2ff;
  --art-opacity: 0.11;
  --panel-sidebar: rgba(13, 14, 24, 0.72);
  --figure-from: #262236;
  --figure-to: #1e2236;
  --title-gradient: linear-gradient(100deg, #f4ebe3 0%, #c9b8ec 34%, #ee8a73 70%, #f0c48a 100%);

  color-scheme: dark;
}

/* ---------- 2) พื้นฐาน ---------- */

/* ฟอนต์ในเครื่อง Windows ไม่โหลดจากเน็ต (D-013): Segoe UI Variable ดูสะอาดแบบ editorial, Leelawadee UI แสดงภาษาไทย */
:root {
  --font-body: "Segoe UI Variable Text", "Segoe UI", "Leelawadee UI", Tahoma, system-ui, sans-serif;
  --font-display: "Segoe UI Variable Display", "Segoe UI", "Leelawadee UI", Tahoma, system-ui, sans-serif;
  --font-mono: "Cascadia Mono", Consolas, "Leelawadee UI", ui-monospace, monospace;  /* ใช้กับสูตรเท่านั้น */
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --sidebar-width: 420px;
  --sidebar-rail: 92px; /* แถบซ้ายตอนซ่อน: โลโก้ 56px + ขอบซ้ายขวา */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* {
  box-sizing: border-box;
}

/* ให้แอตทริบิวต์ hidden ชนะ display ที่กำหนดใน class เสมอ */
[hidden] {
  display: none !important;
}

/* ขนาดตัวอักษรฐาน 17px (106.25% ของค่าเริ่มต้น 16px ของ browser) — ทุกขนาดในไฟล์นี้เป็น rem จึงใหญ่ขึ้นตามกันทั้งหน้า
   ใช้ % แทน px เพื่อให้ยังขยายตามที่ผู้ใช้ตั้งขนาดตัวอักษรใน browser ได้ */
html {
  font-size: 106.25%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text-primary);
  background-color: var(--bg-base);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s ease, color 0.3s ease;
}

h1, h2, h3, h4, h5 {
  line-height: 1.25;
}

code {
  font-family: var(--font-mono);
}

/* กรอบโฟกัสชัดเจนสำหรับผู้ใช้คีย์บอร์ดทุกปุ่ม/ช่อง (เห็นเฉพาะตอนกด Tab ไม่ขึ้นตอนคลิกเมาส์) */
:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}

/* ซ่อนจากตา แต่โปรแกรมอ่านหน้าจอยังอ่านได้ */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ไอคอนเส้น 24×24 สีตามตัวอักษร */
.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ไอคอนจุด 3 จุด (⋯) ต้องใช้เส้นหนาจุดจึงจะมองเห็น */
.icon.dots,
.cpu-more .icon {
  stroke-width: 3;
}

.gradient-text {
  background: var(--title-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent-text);
}

.hint {
  display: block;
  margin: 6px 0 0;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.tag {
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--bg-inset);
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ---------- ปุ่ม ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s var(--ease), box-shadow 0.2s ease, background-color 0.2s ease,
    border-color 0.2s ease, color 0.2s ease, filter 0.2s ease;
}

.button .icon {
  width: 18px;
  height: 18px;
}

.button.primary {
  color: #ffffff;
  background: linear-gradient(135deg, var(--button-from), var(--button-to));
  box-shadow: var(--shadow-button);
}

.button.primary .icon {
  fill: currentColor;
}

.button.primary:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.button.primary:active:not(:disabled) {
  transform: translateY(0);
}

.button.large {
  min-height: 52px;
  padding: 12px 28px;
  font-size: 1rem;
}

.button.ghost {
  color: var(--text-primary);
  background: var(--bg-card);
  border-color: var(--border);
}

.button.ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.button.small {
  min-height: 36px;
  padding: 6px 14px;
  font-size: 0.85rem;
}

.button.danger {
  color: var(--color-error);
}

.button.danger:hover:not(:disabled) {
  background: var(--error-soft);
  border-color: var(--color-error);
}

.button.danger-solid {
  color: #ffffff;
  background: var(--color-error);
}

:root[data-theme="dark"] .button.danger-solid {
  color: #2a0d14;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .button.danger-solid {
    color: #2a0d14;
  }
}

/* ปุ่มที่กดไม่ได้ต้องดูต่างจากปุ่มปกติชัดเจน */
.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

/* ข้อมูลถูกแก้หลัง Run: วงแหวนสีทองรอบปุ่ม Run กะพริบเบา ๆ 2 ครั้ง แล้วค้างไว้ */
.button.primary.needs-run {
  box-shadow: 0 0 0 3px var(--bg-card), 0 0 0 5px var(--accent-gold), var(--shadow-button);
  animation: attention 1.4s ease-in-out 2;
}

/* ปุ่มกลมที่มีแต่ไอคอน */
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.icon-button:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

/* ---------- ช่องกรอก ---------- */

input[type="text"],
select {
  min-height: 44px;
  padding: 9px 14px;
  color: var(--text-primary);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  box-shadow: inset 0 1px 2px rgba(34, 37, 58, 0.04);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.3s ease;
}

input[type="text"]:hover,
select:hover {
  border-color: var(--border-strong);
}

input[type="text"]:focus,
select:focus-visible {
  outline: none;
  border-color: var(--focus-color);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

input.invalid {
  border-color: var(--color-error);
  background: var(--error-soft);
}

input[type="radio"],
input[type="checkbox"] {
  accent-color: var(--accent);
}

.field {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.field > label,
.field > legend {
  display: block;
  margin-bottom: 8px;
  padding: 0;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.number-stepper {
  display: grid;
  grid-template-columns: 44px 68px 44px;
  gap: 6px;
}

.number-stepper input {
  width: 100%;
  text-align: center;
  font-weight: 600;
}

.stepper-button {
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  background: var(--bg-inset);
  color: var(--text-primary);
  font: inherit;
  font-size: 1.2rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.stepper-button:hover:not(:disabled) {
  background: var(--surface-hover);
}

.stepper-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------- 3) พื้นหลัง ---------- */

/* แสงไล่สีจาง ๆ + ดวงอาทิตย์นุ่ม ๆ ติดอยู่กับจอ — แค่เสริมบรรยากาศ ไม่แย่งความเด่นจากการ์ด */
.page-backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(1100px 700px at 92% -12%, var(--glow-1), transparent 62%),
    radial-gradient(900px 640px at -6% 108%, var(--glow-2), transparent 62%);
}

.backdrop-sun {
  position: absolute;
  top: 170px;
  left: calc(50% + var(--main-shift));
  transition: left 0.45s var(--ease);
  width: min(70vw, 760px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, var(--sun-from) 0%, var(--sun-to) 42%, transparent 70%);
  opacity: var(--sun-opacity);
  transform: translate(-50%, -50%);
  animation: sun-breathe 11s ease-in-out infinite;
}

/* แสงส้ม ambient: วงแสงนุ่ม ๆ 2 ดวง (ซ้ายล่าง / ขวากลาง) ขยาย-หดและสว่าง-จางช้า ๆ
   ดวงขวาเริ่มช้ากว่าครึ่งรอบ จึงสลับกันขยาย — ดวงหนึ่งสว่าง อีกดวงจาง แบบไฟ ambient
   ปิดเองเมื่อเครื่องตั้ง "ลดการเคลื่อนไหว" (กฎท้ายไฟล์) */
.backdrop-ember {
  position: absolute;
  width: 620px;
  height: 620px;
  margin: -310px 0 0 -310px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--ember) 0%, transparent 65%);
  opacity: 0.35;
  animation: ember-pulse 14s ease-in-out infinite;
}

/* ดวงซ้ายอยู่ใกล้แถบ CPU และไม่มีอะไรบัง จึงดูสว่างกว่าดวงขวา — ลดความสว่างสูงสุดเหลือราวครึ่งหนึ่ง */
.backdrop-ember.is-left {
  --ember-low: 0.18;
  --ember-peak: 0.5;
  top: 82vh;
  left: calc(var(--sidebar-current) * 0.55);
  transition: left 0.45s var(--ease);
}

.backdrop-ember.is-right {
  top: 48vh;
  left: 96vw;
  animation-delay: -7s;
}

@keyframes sun-breathe {
  0%,
  100% {
    opacity: var(--sun-opacity);
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    opacity: calc(var(--sun-opacity) * 1.3);
    transform: translate(-50%, -51%) scale(1.12);
  }
}

/* --ember-low / --ember-peak = ความสว่างต่ำสุด/สูงสุดของแต่ละดวง (ค่าเริ่มต้น 0.35 / 1) */
@keyframes ember-pulse {
  0%,
  100% {
    opacity: var(--ember-low, 0.35);
    transform: scale(0.85) translate(0, 0);
  }
  50% {
    opacity: var(--ember-peak, 1);
    transform: scale(1.2) translate(2%, -3%);
  }
}

/* ภาพชิป CPU แบบเส้น จาง ๆ หมุนช้ามาก (ไม่แย่งสายตาจากผลลัพธ์) — ปิดเองเมื่อเครื่องตั้ง "ลดการเคลื่อนไหว" */
.backdrop-art-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.backdrop-cpu {
  position: absolute;
  color: var(--art-color);
  opacity: var(--art-opacity);
  overflow: visible;
}

/* ตัวใหญ่: อยู่ใต้ดวงอาทิตย์ กลางพื้นที่ผลลัพธ์ หมุนตามเข็มรอบละ 3 นาที */
.backdrop-cpu.is-main {
  top: 58vh;
  left: calc(50% + var(--main-shift));
  width: min(74vw, 820px);
  height: min(74vw, 820px);
  margin: calc(min(74vw, 820px) / -2) 0 0 calc(min(74vw, 820px) / -2);
  animation: art-spin 180s linear infinite;
  transition: left 0.45s var(--ease);
}

/* ตัวเล็ก: มุมขวาบน หมุนทวนเข็ม เร็วกว่าเล็กน้อย */
.backdrop-cpu.is-corner {
  top: -110px;
  right: -110px;
  width: 360px;
  height: 360px;
  opacity: calc(var(--art-opacity) * 0.8);
  animation: art-spin 120s linear infinite reverse;
}

.art-lines {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.art-dots {
  fill: currentColor;
}

/* วงแหวนเส้นประด้านในหมุนสวนทางกับตัวชิป ให้ภาพดูมีชีวิต */
.art-ring-inner {
  transform-box: view-box;
  transform-origin: 200px 200px;
  animation: art-spin 40s linear infinite reverse;
  /* ชื่อ animation มาจากตัวแปร เพราะวงแหวนนี้อยู่ใน <symbol> ที่แสดงผ่าน <use> (browser ทำสำเนาไว้ใน shadow tree)
     selector ที่อ้างถึง <html> เช่น :root[data-motion="off"] .art-ring-inner เข้าไปไม่ถึงสำเนานั้น
     แต่ค่าตัวแปร CSS สืบทอดผ่าน <use> เข้าไปได้ — ปิด animation พื้นหลังจึงตั้ง --ring-animation: none (D-041) */
  animation-name: var(--ring-animation, art-spin);
}

@keyframes art-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ปิด animation พื้นหลังในหน้าตั้งค่า (theme.js ใส่ data-motion="off" ที่ <html>, D-041)
   ทุกชิ้นหยุดที่ท่าเริ่มต้น (ดวงอาทิตย์ขนาดปกติ แสงส้มจาง ๆ ภาพชิปไม่หมุน) — animation ของปุ่มและผลลัพธ์ยังทำงานตามปกติ */
:root[data-motion="off"] .backdrop-sun,
:root[data-motion="off"] .backdrop-ember,
:root[data-motion="off"] .backdrop-cpu {
  animation: none;
}

/* วงแหวนในภาพชิปหยุดผ่านตัวแปร (ดูเหตุผลที่ .art-ring-inner) */
:root[data-motion="off"] {
  --ring-animation: none;
}

/* ---------- โครงหน้า ---------- */

/* --sidebar-current = ความกว้างแถบซ้ายตอนนี้ (ซ่อนแล้วเหลือแถบแคบ --sidebar-rail) ใช้เป็นความกว้างคอลัมน์
   --shell-pad-right = ขอบขวาของหน้า / --main-shift = ระยะที่กลางพื้นที่ผลลัพธ์อยู่ขวาของกลางจอ (ใช้วางดวงอาทิตย์และภาพชิป) */
body {
  --sidebar-current: var(--sidebar-width);
  --shell-pad-right: 28px;
  --main-shift: calc(var(--sidebar-current) / 2);
}

/* ซ่อนแถบ: ขวาเว้นที่เท่ากับซ้าย (ขอบ 16px + ช่องโลโก้ + ช่องห่าง 28px) พื้นที่ผลลัพธ์จึงอยู่กลางจอพอดี (D-035)
   ถ้าเว้นขวาแค่ 28px เหมือนตอนแสดงแถบ ฝั่งซ้ายจะกว้างกว่าฝั่งขวาราว 108px */
body.sidebar-collapsed {
  --sidebar-current: var(--sidebar-rail);
  --shell-pad-right: calc(16px + var(--sidebar-rail) + 28px);
  --main-shift: 0px;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-current) minmax(0, 1fr);
  transition: grid-template-columns 0.45s var(--ease), padding-right 0.45s var(--ease);
  gap: 28px;
  min-height: 100vh;
  padding: 16px var(--shell-pad-right) 16px 16px;
}

/* ---------- แถบซ้าย: รายการ CPU (ลอยแยกจากเนื้อหา มุมโค้ง พื้นเข้ม) ----------
   ค้างอยู่กับที่สูงเต็มจอ เลื่อนหน้าผลลัพธ์แล้วแถบนี้ไม่เลื่อนตาม ส่วนรายการ CPU เลื่อนขึ้นลงได้ในแถบเอง (D-024) */

.sidebar {
  position: sticky;
  top: 16px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: calc(100vh - 32px);
  padding: 22px 18px 18px;
  overflow: hidden;
  border-radius: 26px;
  /* โปร่งนิดหน่อยให้เห็นพื้นหลัง + เบลอสิ่งที่อยู่ข้างหลัง ตัวอักษรจึงยังอ่านง่าย */
  background: var(--panel-sidebar);
  -webkit-backdrop-filter: blur(8px) saturate(1.2);
  backdrop-filter: blur(8px) saturate(1.2);
  color: var(--sidebar-text);
  box-shadow: var(--shadow-lg), inset 0 1px 0 var(--sidebar-sheen);
  /* ซ่อน/แสดงแถบ: ความกว้างมาจากคอลัมน์ของ .app-shell ส่วนความสูงและขอบใน หดตามตรงนี้ */
  transition: height 0.45s var(--ease), padding 0.45s var(--ease);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 0 18px;
  border-bottom: 1px solid var(--sidebar-border);
  transition: border-color 0.3s ease, padding 0.45s var(--ease);
}

/* โลโก้ = ปุ่มซ่อน/แสดงแถบ CPU: ใหญ่ ไล่สี มีแสงเรือง ชี้เมาส์แล้วยกขึ้นเล็กน้อย */
.brand-mark {
  display: grid;
  flex: none;
  place-items: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 18px;
  background:
    radial-gradient(120% 120% at 30% 0%, rgba(255, 255, 255, 0.28), transparent 55%),
    linear-gradient(135deg, var(--button-from), var(--button-to));
  color: #ffffff;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 12px 26px -10px rgba(225, 98, 72, 0.85);
  transition: transform 0.25s var(--ease), box-shadow 0.25s ease;
}

.brand-mark .icon {
  width: 30px;
  height: 30px;
  stroke-width: 1.7;
}

.brand-mark:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.12),
    0 16px 32px -10px rgba(225, 98, 72, 0.95);
}

/* กดแล้วหมุนหนึ่งรอบ (ซ่อน = ทวนเข็ม, แสดง = ตามเข็ม) ui.js ใส่ class แล้วลบออกเมื่อหมุนเสร็จ */
.brand-mark.spin-close {
  animation: brand-spin-close 0.6s var(--ease);
}

.brand-mark.spin-open {
  animation: brand-spin-open 0.6s var(--ease);
}

@keyframes brand-spin-close {
  0% { transform: rotate(0deg) scale(1); }
  45% { transform: rotate(-200deg) scale(0.86); }
  100% { transform: rotate(-360deg) scale(1); }
}

@keyframes brand-spin-open {
  0% { transform: rotate(0deg) scale(1); }
  45% { transform: rotate(200deg) scale(0.86); }
  100% { transform: rotate(360deg) scale(1); }
}

.brand-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.brand-text strong {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand-text small {
  font-size: 0.86rem;
  color: var(--sidebar-muted);
  white-space: nowrap;
}

/* ---------- แถบซ้ายตอนซ่อน: เหลือแถบแคบที่มีแค่โลโก้ ----------
   เนื้อหาอื่นจางหายก่อนแถบหด (ไม่เห็นการจัดบรรทัดใหม่ระหว่างหด) ตอนแสดงจะค่อย ๆ ปรากฏหลังแถบขยายเสร็จ
   visibility: hidden ทำให้ปุ่มที่ซ่อนอยู่กด Tab ไปไม่ถึง */
.sidebar > :not(.sidebar-brand),
.brand-text {
  transition: opacity 0.25s ease 0.2s, visibility 0s linear 0s;
}

body.sidebar-collapsed .sidebar > :not(.sidebar-brand),
body.sidebar-collapsed .brand-text {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease, visibility 0s linear 0.12s;
}

body.sidebar-collapsed .sidebar-brand {
  padding-bottom: 0;
  border-bottom-color: transparent;
}

/* ตอนซ่อน แถบหดทั้งกว้างและสูง เหลือเป็นกล่องสี่เหลี่ยมเล็ก ๆ ที่มีแค่โลโก้ (ขอบในเท่ากันทุกด้าน)
   กล่องนี้ยังค้างอยู่มุมซ้ายบนตอนเลื่อนหน้า กดโลโก้เพื่อขยายกลับได้ตลอด */
body.sidebar-collapsed .sidebar {
  height: var(--sidebar-rail);
  padding: 18px;
}

/* ตอนเปิดหน้า ใช้สถานะที่จำไว้ทันทีโดยไม่เล่น animation */
body.sidebar-instant .app-shell,
body.sidebar-instant .sidebar,
body.sidebar-instant .sidebar > *,
body.sidebar-instant .brand-text,
body.sidebar-instant .backdrop-sun,
body.sidebar-instant .backdrop-ember,
body.sidebar-instant .backdrop-cpu {
  transition: none !important;
}

.sidebar-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 4px 6px 0;
}

.sidebar-section-head h2 {
  margin: 0;
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--sidebar-muted);
}

.sidebar-count {
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  color: var(--sidebar-muted);
}

/* รายการ CPU (รวมแผงตั้งค่าที่กางอยู่) เลื่อนได้ในแถบเอง โลโก้ด้านบนและปุ่มเพิ่ม CPU ด้านล่างอยู่กับที่
   แถบเลื่อนวางในขอบว่างด้านขวาของแถบ (margin ติดลบ) และจองที่ไว้ตลอด (scrollbar-gutter)
   การ์ดจึงกว้างเท่าเดิมเสมอ ไม่ถูกบีบตอนกางการตั้งค่าแล้วแถบเลื่อนโผล่ */
.cpu-list {
  display: flex;
  flex: 0 1 auto;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  margin: 0 -14px 0 -6px;
  padding: 6px 4px 12px 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--sidebar-hover) transparent;
  list-style: none;
}

/* ---------- การ์ด CPU แบบ 3D ลอย ---------- */

.cpu-item {
  position: relative;
  flex: none;
  transition: transform 0.25s var(--ease);
}

.cpu-item.accent-0 { --cpu-accent: var(--cpu-accent-0); }
.cpu-item.accent-1 { --cpu-accent: var(--cpu-accent-1); }
.cpu-item.accent-2 { --cpu-accent: var(--cpu-accent-2); }
.cpu-item.accent-3 { --cpu-accent: var(--cpu-accent-3); }

/* ชี้เมาส์ = ยกทั้งการ์ดขึ้นเล็กน้อย (การ์ดและปุ่ม ⋯ ไปพร้อมกัน) */
.cpu-item:hover {
  transform: translateY(-3px);
}

.cpu-item.is-active {
  transform: translateY(-2px) scale(1.015);
}

.cpu-card {
  position: relative;
  display: grid;
  /* ไอคอน | ชื่อ + ข้อมูล | ป้ายสถานะ — ขวาสุดเว้น 46px ให้ปุ่ม ⋯ และปุ่มลูกศรที่วางทับมุมการ์ด */
  grid-template-columns: 40px minmax(0, 1fr) auto;
  grid-template-areas: "icon text status";
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 86px; /* สูงพอให้ปุ่ม ⋯ (บน) กับปุ่มลูกศร (ล่าง) ไม่ชนกัน */
  padding: 14px 46px 14px 14px;
  border: 0;
  border-radius: 18px;
  background: var(--sidebar-surface);
  color: var(--sidebar-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  /* ขอบบนสว่าง (แสงตกกระทบ) + เงาใต้การ์ด ให้ดูเป็นแผ่นที่ลอยอยู่ */
  box-shadow: inset 0 1px 0 var(--sidebar-sheen), var(--sidebar-card-shadow);
  transition: background-color 0.25s ease, box-shadow 0.25s ease, color 0.25s ease;
}

.cpu-item:hover .cpu-card {
  box-shadow: inset 0 1px 0 var(--sidebar-sheen), var(--sidebar-card-shadow-hover);
}

/* CPU ที่เลือก: แผ่นสีครีมลอยเด่นที่สุดในแถบ มีแสงเงาสีประจำ CPU จาง ๆ */
.cpu-card[aria-current="true"] {
  background: var(--cpu-active-bg);
  color: var(--cpu-active-text);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    0 0 0 var(--cpu-active-ring) color-mix(in srgb, var(--cpu-accent) 60%, transparent),
    var(--sidebar-active-shadow),
    0 12px 30px -16px var(--cpu-accent);
}

.cpu-card:focus-visible {
  outline-offset: 3px;
}

.cpu-card-icon {
  display: grid;
  grid-area: icon;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--cpu-accent);
  color: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 6px 14px -6px var(--cpu-accent);
}

.cpu-card-text {
  display: flex;
  grid-area: text;
  flex-direction: column;
  min-width: 0;
}

/* line-height 1.45 (ไม่ใช่ 1.3) เพราะช่องนี้ตัดส่วนเกิน หางสระล่าง/ตัวอักษรไทย (ฤ ฎ ฐ ุ ู) จะชิดขอบล่างจนเสี่ยงถูกตัด */
.cpu-card-name {
  overflow: hidden;
  font-weight: 650;
  line-height: 1.45;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ขึ้นบรรทัดใหม่ได้ (ไม่ตัดเป็น …) เพราะป้ายสถานะกินที่ด้านขวา บนมือถือจะเหลือที่น้อย */
.cpu-card-meta {
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--sidebar-muted);
}

.cpu-card[aria-current="true"] .cpu-card-meta {
  color: var(--cpu-active-muted);
}

/* ป้ายสถานะ: Run แล้ว = เขียวทึบ + ✓ / ผลเก่า = ทอง + ลูกศรวน / ยังไม่ Run = ขอบประ ไม่มีพื้น + นาฬิกา
   แยกกันได้ทั้งจากสี รูปทรง (ทึบ / ประ) และไอคอน */
.cpu-card-status {
  display: inline-flex;
  grid-area: status;
  align-items: center;
  gap: 6px;
  padding: 7px 13px 7px 10px;
  border: 1.5px solid transparent;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
}

.cpu-card-status .icon {
  width: 17px;
  height: 17px;
  stroke-width: 2.4;
}

.cpu-card-status.is-done {
  border-color: color-mix(in srgb, var(--status-done-tint) 42%, transparent);
  background: color-mix(in srgb, var(--status-done-tint) 15%, transparent);
  color: var(--status-done-text);
}

.cpu-card-status.is-stale {
  border-color: color-mix(in srgb, var(--status-stale-tint) 45%, transparent);
  background: color-mix(in srgb, var(--status-stale-tint) 16%, transparent);
  color: var(--status-stale-text);
}

.cpu-card-status.is-idle {
  border-style: dashed;
  border-color: var(--status-idle-line);
  background: transparent;
  color: var(--status-idle-text);
}

/* ปุ่ม ⋯ มุมขวาบนของการ์ด เปิด popup รายละเอียด */
.cpu-more {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--sidebar-muted);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.cpu-more:hover {
  background: var(--sidebar-ghost-hover);
  color: var(--sidebar-text);
}

.cpu-item.is-active .cpu-more {
  color: var(--cpu-active-muted);
}

.cpu-item.is-active .cpu-more:hover {
  background: rgba(34, 37, 58, 0.08);
  color: var(--cpu-active-text);
}

.add-cpu-button {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px dashed var(--sidebar-line);
  border-radius: 16px;
  background: transparent;
  color: var(--sidebar-muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.add-cpu-button:hover:not(:disabled) {
  border-color: var(--sidebar-line-hover);
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
}

.add-cpu-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.sidebar-note {
  margin: 0 6px;
  font-size: 0.84rem;
  color: var(--sidebar-muted);
}

/* ---------- dropdown ตั้งค่าการจำลอง (กางใต้การ์ด CPU ที่เลือก) ---------- */

/* กรอบของการ์ด: ปุ่ม ⋯ และปุ่มลูกศรวางทับมุมการ์ดโดยอ้างอิงกรอบนี้ (ไม่ใช่ทั้ง <li> ที่รวมแผงตั้งค่าด้วย) */
.cpu-item-head {
  position: relative;
}

/* ปุ่มลูกศรมุมขวาล่างของการ์ด CPU: กดเพื่อพับ/กางการตั้งค่า (กดที่ตัวการ์ด = เลือก CPU อย่างเดียว) */
.cpu-toggle {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--sidebar-border);
  border-radius: 999px;
  background: var(--sidebar-ghost);
  color: var(--sidebar-muted);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.cpu-toggle .icon {
  width: 18px;
  height: 18px;
  transition: transform 0.3s var(--ease);
}

.cpu-toggle:hover {
  border-color: var(--sidebar-line-hover);
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
}

.cpu-item.is-active .cpu-toggle {
  border-color: var(--border);
  background: transparent;
  color: var(--cpu-active-muted);
}

.cpu-item.is-active .cpu-toggle:hover {
  background: rgba(34, 37, 58, 0.08);
  color: var(--cpu-active-text);
}

.cpu-toggle[aria-expanded="true"] .icon {
  transform: rotate(180deg);
}

/* CPU ที่กางอยู่: การ์ดกับแผงตั้งค่าต่อกันเป็นแผ่นสีครีมแผ่นเดียว ลอยเด่นที่สุดในแถบ */
.cpu-item.is-open {
  border-radius: 20px;
  background: var(--cpu-active-bg);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    0 0 0 var(--cpu-active-ring) color-mix(in srgb, var(--cpu-accent) 60%, transparent),
    var(--sidebar-active-shadow),
    0 14px 34px -18px var(--cpu-accent);
}

/* แผ่นใหญ่ไม่ต้องยกตัวตอนชี้เมาส์ (จะดูโยกไปมาขณะกรอกข้อมูล) */
.cpu-item.is-open,
.cpu-item.is-open:hover {
  transform: none;
}

.cpu-item.is-open .cpu-card,
.cpu-item.is-open:hover .cpu-card {
  background: transparent;
  box-shadow: none;
}

.cpu-panel {
  padding: 0 16px 18px;
  color: var(--text-primary);
  animation: panel-in 0.3s var(--ease) both;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-head .eyebrow {
  margin: 0;
}

/* จำนวนโปรเซส (ซ้าย) คู่กับ Time Quantum (ขวา) */
.panel-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 12px 14px;
}

.cpu-panel .field > label,
.cpu-panel .field > legend {
  margin-bottom: 6px;
  font-size: 0.84rem;
}

.cpu-panel .hint {
  font-size: 0.82rem;
}

/* ---------- ส่วนหัว: ชื่อโปรแกรมกึ่งกลาง ---------- */

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

.hero {
  position: relative;
  padding: 72px 0 40px; /* ปุ่มมุมขวาบนอยู่เหนือหัวข้อ จึงไม่ต้องเว้นด้านข้าง */
  text-align: center;
}

.hero-controls {
  position: absolute;
  top: 12px;
  right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.hero-badge {
  display: inline-block;
  margin: 0;
  padding: 5px 14px;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: var(--bg-card);
  box-shadow: var(--shadow-xs);
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--accent-text);
}

.hero-title {
  margin: 18px 0 14px;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 5vw, 4.1rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  /* ตัวอักษรไล่สีวาดเฉพาะในกรอบของหัวข้อ ถ้าบรรทัดแน่นเกิน หางตัวอักษร (g, p) จะถูกตัด
     จึงใช้ line-height 1.2 และเว้นด้านล่างเล็กน้อย */
  line-height: 1.2;
  padding-bottom: 0.08em;
  /* ทั้งหัวข้อเป็นตัวอักษรไล่สี: หมึก → ม่วง → คอรัล → ทอง */
  background: var(--title-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-title .gradient-text {
  background: none;
  -webkit-background-clip: border-box;
  background-clip: border-box;
  color: inherit;
}

.hero-subtitle {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.hero-dot {
  margin: 0 0.8em;
  color: var(--accent-text);
}

/* ปุ่มภาษา: ตัวที่เลือกเป็นเม็ดสีหมึก */
.language-switch {
  display: inline-flex;
  gap: 2px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  box-shadow: var(--shadow-xs);
}

.language-option {
  min-width: 42px;
  min-height: 30px;
  padding: 3px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.language-option:hover {
  color: var(--text-primary);
}

.language-option[aria-pressed="true"] {
  color: var(--bg-card);
  background: var(--text-primary);
}

/* สวิตช์ธีม: ปุ่มกลมเลื่อนซ้าย-ขวา บังไอคอนฝั่งที่เป็นธีมปัจจุบัน */
.theme-switch {
  position: relative;
  flex: none;
  width: 66px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-muted);
  box-shadow: var(--shadow-xs);
  cursor: pointer;
}

.theme-switch-icon {
  position: absolute;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  transition: opacity 0.2s ease;
}

.theme-switch-icon.sun {
  left: 10px;
}

.theme-switch-icon.moon {
  right: 10px;
}

.theme-switch-thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--button-from), var(--button-to));
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  transition: transform 0.3s var(--ease);
}

.theme-switch[aria-checked="true"] .theme-switch-thumb {
  transform: translateX(28px);
}

.theme-switch[aria-checked="false"] .theme-switch-icon.sun,
.theme-switch[aria-checked="true"] .theme-switch-icon.moon {
  opacity: 0;
}

/* สวิตช์เปิด/ปิดทั่วไป (ใช้กับ animation พื้นหลังในหน้าตั้งค่า D-041)
   ปิด = รางเรียบ ปุ่มกลมซ้าย / เปิด = รางคอรัล ปุ่มกลมขวา (รูปทรงต่างกันด้วย จึงแยกได้แม้มองไม่เห็นสี) */
.toggle-switch {
  position: relative;
  flex: none;
  width: 56px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--bg-inset);
  cursor: pointer;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.toggle-switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  transition: transform 0.3s var(--ease);
}

.toggle-switch[aria-checked="true"] {
  border-color: transparent;
  background: linear-gradient(135deg, var(--button-from), var(--button-to));
}

.toggle-switch[aria-checked="true"] .toggle-switch-thumb {
  transform: translateX(24px);
}

/* ---------- พื้นผิวหลักของแอป (ชั้นที่ 2) ---------- */

.surface {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 30px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: var(--radius-xl);
  /* โปร่งนิดหน่อย (--bg-surface) + เบลอข้างหลัง เห็นสีพื้นหลังและภาพชิปแบบนุ่ม ๆ การ์ดข้างในยังทึบเพื่อให้อ่านง่าย */
  background: var(--bg-surface);
  -webkit-backdrop-filter: blur(8px) saturate(1.15);
  backdrop-filter: blur(8px) saturate(1.15);
  box-shadow: var(--shadow-lg);
}

:root[data-theme="dark"] .surface {
  border-color: var(--border-soft);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .surface {
    border-color: var(--border-soft);
  }
}

/* หัวผลลัพธ์: ชื่อ CPU + ป้ายสถานะ (ซ้าย) / แท็บอัลกอริทึม + ปุ่มจัดการ CPU (ขวา) */
.results-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px 20px;
  padding: 2px 4px 4px;
}

.cpu-heading {
  min-width: 0;
}

.results-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.cpu-name {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 2.6vw, 2.1rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.cpu-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.meta-chip {
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--bg-card);
  box-shadow: var(--shadow-xs);
  font-size: 0.84rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.meta-chip.is-done {
  background: var(--success-soft);
  box-shadow: none;
  color: var(--color-success);
}

.meta-chip.is-stale {
  background: var(--warning-soft);
  box-shadow: none;
  color: var(--color-warning);
}

/* ---------- 4) การ์ดเนื้อหา (ชั้นที่ 3) ---------- */

.card {
  position: relative;
  min-width: 0;
  padding: 26px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-md);
}

/* ---------- ข้อความแจ้งเตือน ---------- */

.error-box {
  margin-bottom: 20px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  background: var(--error-soft);
  animation: fade-up 0.25s ease-out both;
}

.error-box strong {
  color: var(--color-error);
}

.error-box ul {
  margin: 6px 0 0;
  padding-left: 20px;
  font-size: 0.9rem;
}

.stale-note {
  margin: 0;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  background: var(--warning-soft);
  color: var(--color-warning);
  font-size: 0.9rem;
  font-weight: 500;
}

/* ---------- ช่องกรอกในแผงตั้งค่า ---------- */

.cpu-panel .number-stepper {
  grid-template-columns: 40px 56px 40px;
}

.quantum-field input {
  width: 100%;
  text-align: center;
  font-weight: 600;
}

/* เลือกแท็บ RR อยู่: เน้นช่อง TQ ให้รู้ว่าค่านี้มีผลกับผลที่กำลังดู */
.quantum-field.is-active > label {
  color: var(--accent-text);
}

.quantum-field.is-active input {
  border-color: var(--accent);
}

/* หัวข้อ "Burst Time" เหนือการ์ดโปรเซส หน้าตาเดียวกับ label ของช่องอื่นในแผง */
.field-title {
  margin: 0;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.mode-note {
  margin: -8px 0 0;
}

/* แถวโปรเซส 2 คอลัมน์: เตี้ยและแคบ มีครบ 10 โปรเซสก็เป็นแค่ 5 แถว */
.process-deck {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 8px;
}

/* แถวของโปรเซสหนึ่งตัว: จุดสี | ชื่อ | ช่อง BT  (เส้นซ้ายเป็นสีของโปรเซส) */
/* แถวของโปรเซสหนึ่งตัว: จุดสี | ชื่อ | ช่อง BT
   เส้นซ้ายเป็นสีของโปรเซส และพื้นอมสีนั้นจางมาก ๆ ทางซ้าย (ui.js ตั้งค่า --process-color) */
.process-tile {
  display: grid;
  grid-template-columns: 22px auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 8px;
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--process-color, var(--border));
  border-radius: 10px;
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--process-color, transparent) 8%, transparent), transparent 60%),
    var(--bg-card);
  animation: fade-up 0.2s ease-out both;
}

/* จุดสีกลม = ปุ่มเปิดกล่องเลือกสี */
/* จุดสีกลม = ปุ่มเปิดกล่องเลือกสี (มีแสงสะท้อนและแสงเรือง ให้ดูเป็นเม็ดสีที่กดได้) */
/* จุดสีกลม = ปุ่มเปิดกล่องเลือกสี (มีแสงสะท้อนเล็กน้อย ให้ดูเป็นเม็ดสีที่กดได้) */
.color-button {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 2px solid var(--bg-card);
  border-radius: 50%;
  background-image: linear-gradient(145deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0) 60%), var(--process-fill);
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
  transition: transform 0.2s var(--ease);
}

.color-button:hover {
  transform: scale(1.12);
}

.process-name {
  min-width: 22px;
  font-size: 0.86rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.burst-input {
  width: 100%;
  min-height: 32px !important;
  padding: 3px 8px !important;
  border-radius: 8px !important;
  text-align: center;
  font-size: 0.95rem !important;
  font-weight: 600;
}

/* ข้อความในปุ่มอยู่บรรทัดเดียวเสมอ ถ้าแถวไม่พอ (เช่น ภาษาอังกฤษ หรือจอมือถือ) ปุ่มจะขึ้นแถวใหม่ทั้งปุ่มแทนการตกบรรทัดในปุ่ม */
.toolbar-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar-buttons .button {
  flex: 1 1 auto;
  padding: 6px 10px;
  white-space: nowrap;
}

/* ปุ่ม Run เต็มความกว้าง ใต้สุดของแผง */
.run-strip {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.run-strip .button {
  width: 100%;
}

/* ---------- ผลการจำลอง ---------- */

/* แท็บเลือกอัลกอริทึม: กรอบเม็ดยาพื้นการ์ด มีขอบและเงา ตัวที่เลือกเป็นเม็ดไล่สีคอรัล (สีเดียวกับปุ่ม RUN) ตัวขาว
   ตัวที่ไม่ได้เลือกใช้ตัวอักษรเข้มกว่าเดิม ชี้เมาส์แล้วมีพื้นจาง ๆ — เห็นชัดว่าเป็นปุ่มที่กดได้ */
.view-tabs {
  display: inline-flex;
  gap: 4px;
  max-width: 100%;
  padding: 5px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.view-tab {
  flex: none;
  min-height: 40px;
  padding: 8px 20px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease, transform 0.2s var(--ease);
}

.view-tab:hover:not(:disabled):not([aria-pressed="true"]) {
  background: var(--surface-hover);
  color: var(--text-primary);
}

/* ต้นไล่สีเข้มลง 12% (ผสมดำ) ให้ตัวอักษรขาวขนาดปกติได้ contrast ≥ 4.5:1 ทั้งสองธีม */
.view-tab[aria-pressed="true"] {
  background: linear-gradient(135deg, color-mix(in srgb, var(--button-from) 88%, #000000), var(--button-to));
  color: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), var(--shadow-button);
}

.view-tab:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ปุ่ม ⋯ (จัดการ CPU) ข้างแท็บ: ขนาดเท่าความสูงของแท็บ มีขอบและเงาเหมือนกัน ชี้เมาส์แล้วเป็นสีคอรัล */
.results-actions .icon-button {
  width: 52px;
  height: 52px;
  border-color: var(--border);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.2s var(--ease);
}

.results-actions .icon-button:hover {
  border-color: var(--accent);
  background: var(--bg-card);
  color: var(--accent-text);
  transform: translateY(-1px);
}

/* ชื่อเต็ม + คำอธิบายสั้นของอัลกอริทึม + ปุ่ม "วิธีทำงาน" */
.algorithm-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  padding: 18px 22px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}

.algorithm-text {
  flex: 1 1 320px;
  min-width: 0;
}

.algorithm-name {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 650;
}

.algorithm-summary {
  margin: 2px 0 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.empty-state {
  padding: 52px 24px;
  text-align: center;
}

.empty-state h4 {
  margin: 20px 0 6px;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 650;
}

.empty-state p {
  max-width: 440px;
  margin: 0 auto;
  font-size: 0.92rem;
  color: var(--text-muted);
}

/* Gantt chart จำลองเล็ก ๆ ที่หายใจช้า ๆ */
.empty-art {
  display: inline-flex;
  gap: 4px;
}

.empty-art span {
  display: block;
  height: 22px;
  border-radius: 7px;
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0) 60%), var(--process-fill);
  transform-origin: left center;
  animation: empty-bar 3s ease-in-out infinite;
}

/* สีของ P1..P5 ใน DEFAULT_COLORS (ui.js) ไล่สีแบบเดียวกับแถบ Gantt จริง */
.empty-art span:nth-child(1) { width: 46px; --process-color: #ff6b6b; background-color: #ff6b6b; }
.empty-art span:nth-child(2) { width: 28px; --process-color: #4d8dff; background-color: #4d8dff; animation-delay: 150ms; }
.empty-art span:nth-child(3) { width: 58px; --process-color: #20c9b7; background-color: #20c9b7; animation-delay: 300ms; }
.empty-art span:nth-child(4) { width: 34px; --process-color: #b276ff; background-color: #b276ff; animation-delay: 450ms; }
.empty-art span:nth-child(5) { width: 22px; --process-color: #ffb547; background-color: #ffb547; animation-delay: 600ms; }

.results-view {
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: fade-up 0.35s var(--ease) both;
}

/* วาดใหม่เพราะเปลี่ยนสีหรือภาษา: ไม่ต้องเล่น animation ซ้ำ */
.results-view.is-static,
.results-view.is-static * {
  animation: none !important;
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px 16px;
  margin-bottom: 14px;
}

.card-eyebrow {
  margin: 0 0 2px;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent-text);
}

.card-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 650;
}

.card-description {
  margin: 0 0 12px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--bg-inset);
  font-size: 0.84rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.pill.accent {
  background: var(--accent-soft);
  color: var(--accent-text);
}

/* ---------- Gantt chart ---------- */

/* เว้นด้านล่างให้ตัวเลขเวลาใต้แถบ (ตัวเลขวางแบบ absolute จึงต้องเผื่อที่เอง)
   overflow-y: hidden กันแถบเลื่อนแนวตั้งโผล่ ถ้าตัวอักษรใหญ่กว่าที่เผื่อไว้เล็กน้อย */
.gantt-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  margin: 0 -4px;
  padding: 10px 14px 44px;
}

.gantt {
  display: flex;
  gap: 4px;
  height: 60px;
}

.gantt-slot {
  position: relative;
  flex-basis: 0;
  min-width: 40px;
  border-radius: 12px;
  outline-offset: 3px;
  cursor: default;
}

/* ไล่สีของโปรเซส (D-044, D-045): ทุกที่ที่วาดสีโปรเซสเป็นพื้น ไล่จาก "สีอ่อน" (มุมซ้ายบน) → "สีของโปรเซส" (มุมขวาล่าง)
   สีอ่อน = สีเดียวกันที่สว่างขึ้น 0.06 และหมุนเฉดไป −20° คำนวณด้วย CSS relative color จึงใช้ได้กับสีที่ผู้ใช้เลือกเองด้วย
   ไล่ไปทางสว่าง (ไม่ใช่ทางมืด) เพราะตัวอักษรบนแถบเป็นสีเข้ม ปลายที่สว่างกว่าจึงอ่านง่ายเท่าเดิมหรือดีขึ้น */
.gantt-bar,
.swatch,
.color-button,
.preset-color,
.kpi-bar,
.kpi-strip-piece,
.empty-art span,
.figure-gradient {
  --process-color-light: var(--process-color); /* browser เก่าที่ไม่รู้จัก oklch(from …) = สีพื้นเรียบ */
  --process-fill: linear-gradient(135deg, var(--process-color-light), var(--process-color));
}

@supports (color: oklch(from red l c h)) {
  .gantt-bar,
  .swatch,
  .color-button,
  .preset-color,
  .kpi-bar,
  .kpi-strip-piece,
  .empty-art span,
  .figure-gradient {
    --process-color-light: oklch(from var(--process-color) calc(l + 0.06) c calc(h - 20));
  }
}

/* ภาพ SVG ใน popup ใช้ <linearGradient class="figure-gradient"> ที่ modals.js สร้าง */
.figure-gradient .gradient-start {
  stop-color: var(--process-color-light);
}

.figure-gradient .gradient-end {
  stop-color: var(--process-color);
}

.gantt-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  border-radius: 12px;
  /* สีพื้นมาจาก ui.js (สีของโปรเซส) ชั้นบนเป็นแสงสะท้อนด้านบนจาง ๆ ให้แถบมีมิติ ชั้นล่างเป็นการไล่สี */
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0) 55%), var(--process-fill);
  /* แสงเรืองสีเดียวกับแถบใต้แถบ พอให้ดูลอย แต่ไม่ฟุ้งจนรก */
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 9px 18px -10px color-mix(in srgb, var(--process-color, #000) 75%, transparent);
  /* ตัวอักษรสีเข้มเสมอทั้งสองธีม (D-045) — สีเริ่มต้นเป็นโทนสว่าง ทุกสีได้ contrast กับสีนี้ ≥ 4.5:1
     เงาสีขาวบาง ๆ ช่วยเมื่อผู้ใช้เลือกสีเข้มเอง */
  color: var(--process-text);
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.3);
  font-size: 0.92rem;
  font-weight: 650;
  transform-origin: left center;
  /* backwards: ใช้ค่าเริ่มของ animation ระหว่างรอ แต่ไม่ค้างค่าสุดท้าย เอฟเฟกต์ตอนชี้เมาส์จึงยังทำงาน */
  animation: bar-in 0.5s var(--ease) backwards;
  transition: transform 0.2s var(--ease), filter 0.2s ease, box-shadow 0.2s ease;
}

.gantt-slot:hover .gantt-bar,
.gantt-slot:focus-visible .gantt-bar {
  transform: translateY(-3px);
  filter: brightness(1.06);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 13px 24px -10px color-mix(in srgb, var(--process-color, #000) 85%, transparent);
}

/* ตัวเลขเวลาใต้ขอบซ้ายของแต่ละแถบ (และขอบขวาของแถบสุดท้าย) พร้อมขีดบอกตำแหน่ง */
.gantt-time {
  position: absolute;
  top: calc(100% + 12px);
  left: -2px;
  font-size: 0.84rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  transform: translateX(-50%);
}

.gantt-time::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 50%;
  width: 1px;
  height: 5px;
  background: var(--border-strong);
}

.gantt-time.end {
  left: auto;
  right: -2px;
  transform: translateX(50%);
}

/* ลำดับการได้ CPU: เม็ดสีของโปรเซสเรียงตาม Gantt chart มีลูกศรเล็ก ๆ คั่นระหว่างเม็ด */
.order-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 22px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}

.order-item {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 4px 9px;
  border-radius: 999px;
  background: var(--bg-inset);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ลูกศรอยู่ในช่องว่างระหว่างเม็ด (ไม่ใช่ข้อความ โปรแกรมอ่านหน้าจออ่านเป็นรายการตามลำดับอยู่แล้ว) */
.order-item + .order-item:not(.total)::before {
  content: "›";
  position: absolute;
  left: -15px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
}

.order-item .swatch {
  margin-right: 0;
}

.order-id {
  font-weight: 650;
}

.order-time {
  color: var(--text-muted);
}

.order-item.total {
  padding-left: 12px;
  font-weight: 600;
  color: var(--accent-text);
}

/* จุดสีของโปรเซส (ตาราง, ลำดับการได้ CPU, tooltip, สูตร): วงกลมมีแสงสะท้อนมุมบนเล็กน้อย */
.swatch {
  display: inline-block;
  flex: none;
  width: 12px;
  height: 12px;
  margin-right: 8px;
  border-radius: 50%;
  vertical-align: -1px;
  background-image: linear-gradient(145deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0) 60%), var(--process-fill);
}

/* กล่องรายละเอียดของแถบ (position: fixed ui.js คำนวณตำแหน่งจากแถบที่ชี้อยู่) */
.gantt-tooltip {
  position: fixed;
  z-index: 70;
  min-width: 170px;
  padding: 12px 14px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  box-shadow: var(--shadow-lg);
  font-size: 0.86rem;
  pointer-events: none;
}

.tooltip-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.tooltip-title .swatch {
  margin-right: 0;
}

.tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--text-secondary);
}

.tooltip-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

/* ---------- ค่าสรุป 4 ช่อง ---------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.kpi-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 20px 20px 18px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  /* พื้นการ์ดอมสีของค่านั้นจาง ๆ ที่มุมบน แล้วจางเป็นสีการ์ดปกติ (สดแต่ไม่รก ตัวเลขยังอ่านง่าย) */
  background:
    radial-gradient(120% 90% at 100% 0%, color-mix(in srgb, var(--kpi-color) 14%, transparent), transparent 60%),
    var(--bg-card);
  box-shadow: var(--shadow-md);
  animation: fade-up 0.4s var(--ease) both;
}

/* เส้นสีสั้น ๆ มุมซ้ายบน บอกว่าเป็นค่าไหน (ไม่ใช้พื้นสีทั้งการ์ด จะได้ไม่รก) */
.kpi-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 22px;
  width: 44px;
  height: 4px;
  border-radius: 0 0 4px 4px;
  background: linear-gradient(90deg, var(--kpi-color), var(--kpi-color-2));
}

.kpi-card:nth-child(2) { animation-delay: 60ms; }
.kpi-card:nth-child(3) { animation-delay: 120ms; }
.kpi-card:nth-child(4) { animation-delay: 180ms; }

/* สีของค่าสรุป 4 ช่อง: ส้ม / ม่วง / เขียวมรกต / ฟ้า แบบสด (D-019 — ผู้ใช้ชอบแล้ว จึงคงไว้)
   --kpi-color = สีหลัก, --kpi-color-2 = สีปลายของ gradient (เลื่อนเฉดเล็กน้อยให้มีมิติ) */
.kpi-orange { --kpi-color: #ff8500; --kpi-color-2: #ff4d4d; }
.kpi-violet { --kpi-color: #8545ff; --kpi-color-2: #c04bff; }
.kpi-teal { --kpi-color: #00c49a; --kpi-color-2: #00d4ff; }
.kpi-cyan { --kpi-color: #008fff; --kpi-color-2: #4f46e5; }

.kpi-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ไอคอนในกล่องไล่สี + แสงเรืองสีเดียวกันจาง ๆ ด้านล่าง */
.kpi-top .icon {
  width: 38px;
  height: 38px;
  padding: 9px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--kpi-color), var(--kpi-color-2));
  color: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 8px 18px -8px var(--kpi-color);
}

.kpi-labels {
  min-width: 0;
}

.kpi-title {
  display: block;
  font-size: 0.9rem;
  font-weight: 650;
  line-height: 1.25;
}

.kpi-full {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* แถวล่างของการ์ด: ตัวเลขทางซ้าย กราฟจิ๋วทางขวา วางชิดฐานเดียวกัน */
.kpi-body {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
}

.kpi-value {
  flex: none;
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.05;
  animation: value-pop 0.45s var(--ease) both;
}

/* กราฟจิ๋วสีของโปรเซส (ภาพประกอบ ค่าจริงอยู่ในตาราง) */
.kpi-chart {
  display: flex;
  flex: 1 1 auto;
  max-width: 150px;
  min-width: 0;
  height: 38px;
  overflow: hidden; /* ช่วงเยอะมาก (เช่น RR TQ = 1) แท่งเล็กสุดรวมกันยาวเกินกรอบ ให้ตัดในกรอบ ไม่ล้นออกนอกการ์ด */
}

/* หนึ่งแท่งต่อโปรเซส สูงตามค่า */
.kpi-bars {
  align-items: flex-end;
  gap: 3px;
}

.kpi-bar {
  flex: 1 1 0;
  max-width: 14px;
  min-width: 2px;
  border-radius: 3px 3px 1px 1px;
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 70%), var(--process-fill);
  transform-origin: bottom;
  animation: kpi-grow 0.5s var(--ease) both;
}

/* แถบ Gantt จิ๋ว: ช่วงละสี มีช่องเล็ก ๆ คั่น เห็นจุดที่ CPU สลับโปรเซส */
.kpi-strip {
  align-self: center;
  gap: 2px;
  height: 14px;
  margin-bottom: 8px;
}

.kpi-strip-piece {
  flex-basis: 0;
  min-width: 2px;
  border-radius: 3px;
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 70%), var(--process-fill);
  transform-origin: left;
  animation: kpi-grow-x 0.5s var(--ease) both;
}

@keyframes kpi-grow {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}

@keyframes kpi-grow-x {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

/* ---------- ตาราง ---------- */

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.toggle input {
  width: 16px;
  height: 16px;
}

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
  font-variant-numeric: tabular-nums;
}

/* ตารางผลลัพธ์: ความกว้างคอลัมน์คงที่ (ui.js ใส่ <colgroup>) เปิด/ปิดวิธีคำนวณแล้วคอลัมน์ไม่ขยับ
   TAT / WT กว้างพอสำหรับสูตรที่ยาวที่สุด (10 โปรเซส BT 100 → "1000 − 100 = 900")
   จอแคบกว่าความกว้างขั้นต่ำ ตารางเลื่อนแนวนอนในกรอบแทนการบีบคอลัมน์ */
.result-table {
  min-width: 760px;
  table-layout: fixed;
}

.result-table .col-process { width: 15%; }
.result-table .col-at,
.result-table .col-bt,
.result-table .col-st,
.result-table .col-ct { width: 11%; }
.result-table .col-tat,
.result-table .col-wt { width: 20.5%; }

th,
td {
  padding: 13px 18px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border-soft);
}

thead th {
  background: var(--bg-inset);
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

/* หัวคอลัมน์ = ปุ่ม: ตัวย่อขีดเส้นประ + วงกลม "?" เล็ก ๆ บอกว่ากดดูคำอธิบายได้ */
.th-help {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: -4px -8px;
  padding: 4px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.th-help-text {
  border-bottom: 1px dotted currentColor;
}

.th-help-mark {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  opacity: 0.7;
}

.th-help:hover,
.th-help[aria-expanded="true"] {
  background: var(--surface-hover);
  color: var(--accent-text);
}

.th-help:hover .th-help-mark,
.th-help[aria-expanded="true"] .th-help-mark {
  opacity: 1;
}

/* กล่องคำอธิบายหัวคอลัมน์ (position: fixed — ui.js วางใต้หัวคอลัมน์ที่กด และเลื่อนตามเมื่อเลื่อนหน้า) */
.column-help {
  position: fixed;
  z-index: 45;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(340px, calc(100vw - 32px));
  padding: 16px 18px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-popup);
  font-size: 0.9rem;
  white-space: normal;
  animation: pop-in 0.2s var(--ease) both;
}

.column-help-title {
  margin-bottom: 4px;
  font-size: 0.95rem;
  line-height: 1.4;
}

.column-help-label {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-muted);
}

.column-help code {
  display: block;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--bg-inset);
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.column-help-rule {
  font-weight: 600;
}

.column-help-example {
  color: var(--accent-text);
  font-weight: 600;
}

.column-help-tip {
  margin: 6px 0 0;
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--text-muted);
}

tbody th {
  font-weight: 600;
}

/* ช่องชื่อโปรเซส: แถบสีของโปรเซสด้านซ้าย (ui.js ตั้งค่า --process-color) */
tbody th.process-cell {
  box-shadow: inset 3px 0 0 var(--process-color, transparent);
}

tbody tr {
  transition: background-color 0.15s ease;
}

tbody tr:hover {
  background: var(--bg-inset);
}

tbody tr:last-child th,
tbody tr:last-child td {
  border-bottom: 0;
}

.num {
  text-align: right;
}

/* TAT และ WT เป็นค่าหลักของโจทย์ จึงใช้สีเน้น */
.key-metric {
  font-weight: 600;
  color: var(--accent-text);
}

.formula {
  font-weight: 400;
  color: var(--text-muted);
}

tfoot th,
tfoot td {
  border-top: 1px solid var(--border);
  border-bottom: 0;
  background: var(--bg-inset);
  font-weight: 650;
}

tfoot td {
  color: var(--accent-text);
}

.best-row th,
.best-row td {
  background: var(--success-soft);
}

.badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--color-success);
  color: var(--badge-text);
  font-size: 0.82rem;
  font-weight: 600;
  vertical-align: 1px;
}

/* ---------- สูตรการคำนวณ (accordion พับ/กางได้) ---------- */

.formula-card {
  padding: 0;
}

.formula-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 26px;
  border-radius: var(--radius-lg);
  list-style: none;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.formula-summary:hover {
  background: var(--bg-inset);
}

.formula-summary::-webkit-details-marker {
  display: none;
}

/* วงกลมมีลูกศร บอกว่ากางหรือพับอยู่ */
.formula-summary::after {
  content: "";
  flex: none;
  width: 9px;
  height: 9px;
  margin-right: 8px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg);
  transition: transform 0.25s var(--ease);
}

.formula-card[open] .formula-summary::after {
  transform: rotate(-135deg);
}

.formula-card[open] .formula-summary {
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.formula-body {
  padding: 4px 26px 26px;
  animation: fade-up 0.3s var(--ease) both;
}

.formula-picker {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.formula-picker .swatch {
  margin-right: 0;
}

.formula-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.formula-tile {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: var(--bg-inset);
}

.formula-tile-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
}

.formula-name {
  padding: 1px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 0.84rem;
  font-weight: 650;
  white-space: nowrap;
}

.formula-meaning {
  font-size: 0.86rem;
  color: var(--text-secondary);
}

.formula-line {
  display: grid;
  gap: 2px;
}

.formula-line-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.formula-line code {
  font-size: 0.85rem;
  color: var(--text-primary);
  overflow-wrap: anywhere;
}

.formula-example code {
  font-weight: 600;
  color: var(--accent-text);
}

/* ---------- เปรียบเทียบ ---------- */

.card-subtitle {
  margin: 0 0 18px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.bar-group {
  display: grid;
  grid-template-columns: 130px 1fr;
  align-items: center;
  gap: 8px 16px;
}

.bar-group-label {
  grid-row: span 2;
  font-weight: 650;
}

.bar-row {
  display: grid;
  grid-template-columns: 66px 1fr minmax(96px, auto);
  align-items: center;
  gap: 12px;
  font-size: 0.86rem;
}

.bar-metric {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.bar-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--track-bg);
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  transform-origin: left center;
  animation: bar-in 0.7s var(--ease) backwards;
}

.bar-wt .bar-fill {
  background: linear-gradient(90deg, #ff8500, #ff438c);
  box-shadow: 0 4px 12px -4px rgba(255, 67, 140, 0.55);
}

.bar-tat .bar-fill {
  background: linear-gradient(90deg, #8545ff, #008fff);
  box-shadow: 0 4px 12px -4px rgba(0, 143, 255, 0.55);
}

.bar-value {
  display: inline-flex;
  align-items: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.note {
  margin: 14px 0 0;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.note.muted {
  margin-top: 4px;
  color: var(--text-muted);
}

/* ---------- เปรียบเทียบ CPU (D-039, js/compare.js) ---------- */

/* ปุ่มในแถบซ้าย ใต้ "เพิ่ม CPU" (ผู้ใช้ขอ — D-039):
   ยังไม่ได้เปิดหน้าเปรียบเทียบ = เม็ดไล่สีคอรัล (ชวนให้กด) / เปิดอยู่ = พื้นเรียบไม่มีสี (กดซ้ำเพื่อปิด) */
.compare-cpus-button {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 16px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--button-from) 88%, #000000), var(--button-to));
  color: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), var(--shadow-button);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, filter 0.2s ease;
}

.compare-cpus-button:hover:not([aria-pressed="true"]) {
  filter: brightness(1.08);
}

.compare-cpus-button[aria-pressed="true"] {
  border-color: var(--sidebar-line);
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
  box-shadow: none;
}

.compare-cpus-button[aria-pressed="true"]:hover {
  border-color: var(--sidebar-line-hover);
}

.compare-intro {
  max-width: 560px;
  margin: 8px 0 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* checkbox เลือก CPU: เม็ดเรียงต่อกัน ขึ้นแถวใหม่เมื่อไม่พอ */
.compare-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.compare-pick {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  max-width: 100%;
  padding: 9px 16px 9px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-card);
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.compare-pick:hover {
  border-color: var(--border-strong);
}

.compare-pick:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.compare-pick input {
  flex: none;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
  cursor: inherit;
}

/* CPU ที่ยังไม่ Run เลือกไม่ได้ (ยังไม่มีผล) */
.compare-pick.is-idle {
  opacity: 0.55;
  cursor: not-allowed;
}

.compare-pick-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.35;
}

.compare-pick-name {
  font-weight: 650;
  overflow-wrap: anywhere;
}

.compare-pick-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.compare-pick.is-stale .compare-pick-meta {
  color: var(--color-warning);
}

.compare-empty {
  padding: 36px 24px;
}

.compare-empty h4 {
  margin-top: 0;
}

.compare-empty p {
  max-width: 520px;
}

/* กราฟ: กลุ่มละ 3 แท่ง (FCFS / SJF / RR) ชื่อ CPU คร่อม 3 แถว */
.bar-group.is-triple .bar-group-label {
  grid-row: span 3;
}

.compare-group-label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
}

.compare-group-name {
  overflow-wrap: anywhere;
}

.compare-group-meta {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
}

.compare-stale-tag {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--warning-soft);
  color: var(--color-warning);
  font-size: 0.8rem;
  font-weight: 600;
}

th .compare-stale-tag {
  margin-left: 8px;
}

.bar-fcfs .bar-fill {
  background: linear-gradient(90deg, #ff8500, #ff438c);
  box-shadow: 0 4px 12px -4px rgba(255, 67, 140, 0.55);
}

.bar-sjf .bar-fill {
  background: linear-gradient(90deg, #8545ff, #008fff);
  box-shadow: 0 4px 12px -4px rgba(0, 143, 255, 0.55);
}

.bar-rr .bar-fill {
  background: linear-gradient(90deg, #08a76f, #00b3c7);
  box-shadow: 0 4px 12px -4px rgba(0, 179, 199, 0.55);
}

/* ตาราง: ชุด BT ยาวได้ถึง 10 ตัว จึงยอมให้ขึ้นบรรทัดใหม่ (ช่องอื่น nowrap ตามตารางทั่วไป) */
.cpu-compare-table .compare-bt {
  min-width: 140px;
  white-space: normal;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  color: var(--text-secondary);
}

.cpu-compare-table td.is-lowest {
  background: var(--success-soft);
  color: var(--color-success);
  font-weight: 700;
}

/* ชื่อ CPU ในตาราง = ปุ่มเปิดผลของ CPU นั้น หน้าตาเหมือนลิงก์ */
.compare-open-cpu {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-text);
  font: inherit;
  font-weight: 650;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, currentColor 40%, transparent);
  text-underline-offset: 3px;
  cursor: pointer;
}

.compare-open-cpu:hover {
  text-decoration-color: currentColor;
}

.note.warning-note {
  color: var(--color-warning);
}

/* ---------- 5) กล่องเลือกสี ---------- */

/* position: fixed = วางตามตำแหน่งบนจอ ui.js ขยับตามจุดสีทุกครั้งที่รายการ CPU หรือหน้าเว็บเลื่อน */
.color-popover {
  position: fixed;
  z-index: 40;
  width: 260px;
  padding: 16px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-popup);
  animation: pop-in 0.2s var(--ease) both;
}

.color-popover-title {
  display: block;
  margin-bottom: 10px;
}

.color-popover-section {
  margin-bottom: 8px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-muted);
}

.preset-colors {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.preset-color {
  aspect-ratio: 1;
  min-height: 34px;
  border: 0;
  border-radius: 10px;
  background-image: linear-gradient(145deg, rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0) 60%), var(--process-fill);
  cursor: pointer;
  transition: transform 0.2s var(--ease), box-shadow 0.2s ease;
}

.preset-color:hover {
  transform: scale(1.08);
}

.preset-color[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--bg-card), 0 0 0 4px var(--text-primary);
}

.custom-color {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
  font-size: 0.88rem;
  cursor: pointer;
}

.custom-color code {
  margin-left: auto;
  font-size: 0.84rem;
  color: var(--text-muted);
}

input[type="color"] {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: none;
  cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 3px;
}

input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 7px;
}

/* ---------- popup (ชั้นบนสุด) ---------- */

/* <dialog> เองโปร่งใส เนื้อหาอยู่ใน .modal-panel — คลิกนอกแผงจึงนับเป็นคลิกที่พื้นหลัง (ปิด popup) */
.modal {
  width: min(580px, calc(100vw - 32px));
  max-width: none;
  max-height: none;
  margin: auto;
  padding: 0;
  overflow: visible;
  border: 0;
  background: transparent;
  color: var(--text-primary);
}

.modal-small {
  width: min(480px, calc(100vw - 32px));
}

.modal::backdrop {
  background: rgba(24, 20, 36, 0.42);
  backdrop-filter: blur(5px);
  animation: fade-in 0.25s ease-out both;
}

.modal-panel {
  max-height: calc(100vh - 48px);
  padding: 30px;
  overflow-y: auto;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl);
  background: var(--bg-card);
  box-shadow: var(--shadow-popup);
  animation: modal-in 0.35s var(--ease) both;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.modal-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

/* ภาพประกอบเป็นเนื้อหาหลักของ popup วางบนพื้นไล่สีพีช → ลาเวนเดอร์จาง ๆ */
.modal-figure {
  margin: 0 0 18px;
  padding: 18px 18px 14px;
  border-radius: var(--radius-lg);
  background: linear-gradient(150deg, var(--figure-from), var(--figure-to));
}

.modal-figure figcaption {
  margin-top: 10px;
  font-size: 0.84rem;
  text-align: center;
  color: var(--text-muted);
}

.figure-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  font-family: var(--font-body);
}

.figure-axis {
  stroke: var(--border-strong);
  stroke-width: 1;
}

.figure-bar.is-empty {
  opacity: 0.3;
}

.figure-value {
  fill: var(--text-primary);
  font-size: 11px;
  font-weight: 600;
}

.figure-label {
  fill: var(--text-muted);
  font-size: 10.5px;
}

.figure-chip-text {
  fill: var(--process-text);
  font-size: 12px;
  font-weight: 650;
}

.figure-arrow {
  fill: none;
  stroke: var(--accent-text);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.figure-arrow.dashed {
  stroke-dasharray: 5 5;
  opacity: 0.8;
}

.figure-cpu {
  fill: #20233a;
}

.figure-cpu-text {
  fill: #f1ecf2;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.modal-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.modal-facts.two-columns {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 18px;
}

.modal-fact {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-inset);
}

.modal-fact dt {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.modal-fact dd {
  margin: 4px 0 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.modal-facts.two-columns dd {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.status-text.is-done {
  color: var(--color-success);
}

.status-text.is-stale {
  color: var(--color-warning);
}

.modal-section {
  margin-top: 22px;
}

.modal-section-title {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 650;
}

.warning-text {
  color: var(--color-warning);
}

.pill-row {
  display: inline-block;
  margin: -6px 0 16px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 0.86rem;
  font-weight: 600;
}

.modal-steps {
  margin: 0;
  padding-left: 22px;
  color: var(--text-secondary);
}

.modal-steps li {
  margin-bottom: 6px;
  padding-left: 4px;
}

.modal-steps li::marker {
  color: var(--accent-text);
  font-weight: 700;
}

.rename-form {
  margin-bottom: 20px;
}

.rename-form label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.rename-row {
  display: flex;
  gap: 10px;
}

.rename-row input {
  flex: 1;
  min-width: 0;
}

.modal-actions-wrap {
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--border-soft);
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

/* ปุ่มลบอยู่ฝั่งซ้าย แยกจากปุ่มอื่น กันกดพลาด */
.modal-actions .danger {
  margin-right: auto;
}

.confirm-box {
  margin-top: 14px;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: var(--error-soft);
  animation: fade-up 0.2s ease-out both;
}

.confirm-box p {
  margin: 0 0 12px;
  font-size: 0.92rem;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.settings-list {
  display: flex;
  flex-direction: column;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 0;
  border-bottom: 1px solid var(--border-soft);
}

.settings-row .hint {
  margin-top: 2px;
}

/* ข้อความอธิบายทางซ้ายยอมขึ้นบรรทัดใหม่แทน ปุ่ม/สวิตช์ทางขวาจึงไม่ถูกบีบจนตัวอักษรในปุ่มตกบรรทัด */
.settings-row > :first-child {
  flex: 1 1 auto;
  min-width: 0;
}

.settings-row > :last-child {
  flex: none;
  white-space: nowrap;
}

.settings-row.danger-zone {
  border-bottom: 0;
}

/* ---------- ท้ายหน้า ---------- */

.site-footer {
  padding: 30px 8px 24px;
  font-size: 0.86rem;
  text-align: center;
  color: var(--text-muted);
}

/* ลิงก์โดเมนท้ายหน้า (D-047): สีเดียวกับข้อความ ขีดเส้นใต้ตอนชี้ */
.footer-link {
  color: inherit;
  text-decoration: none;
}

.footer-link:hover,
.footer-link:focus-visible {
  color: var(--text-primary);
  text-decoration: underline;
}

/* ---------- 6) Animation (นุ่ม สั้น ไม่วูบวาบ) ---------- */

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* popup: จางเข้า + ลอยขึ้นเล็กน้อย */
@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* แผงตั้งค่า: จางเข้า + เลื่อนลงเล็กน้อย เหมือน dropdown ที่กางออก */
@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes bar-in {
  from {
    opacity: 0;
    transform: scaleX(0);
  }
  to {
    opacity: 1;
    transform: scaleX(1);
  }
}

@keyframes empty-bar {
  0%, 100% { transform: scaleX(1); }
  50% { transform: scaleX(0.7); }
}

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

@keyframes attention {
  50% {
    box-shadow: 0 0 0 3px var(--bg-card), 0 0 0 8px var(--accent-gold), var(--shadow-button);
  }
}

/* ---------- Responsive ---------- */

/* โน้ตบุ๊ก: ค่าสรุปเหลือแถวละ 2 ช่อง และเว้นที่ให้ปุ่มมุมขวาบนไม่ทับหัวข้อ */
@media (max-width: 1280px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hero {
    padding: 80px 0 36px;
  }
}

/* แท็บเล็ตและมือถือ: เรียงเป็นคอลัมน์เดียว ชื่อโปรแกรม → รายการ CPU (พร้อมแผงตั้งค่า) → ผลลัพธ์
   .main ใช้ display: contents เพื่อให้ส่วนหัว ผลลัพธ์ และท้ายหน้า เรียงลำดับร่วมกับแถบ CPU ได้ด้วย order */
@media (max-width: 1024px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 12px 16px;
  }

  .main {
    display: contents;
  }

  .hero {
    order: 1;
    padding: 64px 0 4px;
  }

  .sidebar {
    position: static;
    order: 2;
    height: auto;
    overflow: visible;
  }

  /* ซ่อนแถบบนจอแคบ: เหลือแถวโลโก้ + ชื่อ (เนื้อหาที่ซ่อนไม่กินที่) */
  body.sidebar-collapsed .sidebar > :not(.sidebar-brand) {
    display: none;
  }

  body.sidebar-collapsed .brand-text {
    opacity: 1;
    visibility: visible;
  }

  body.sidebar-collapsed .sidebar {
    height: auto;
  }

  /* จอแคบ: แถบ CPU อยู่ในคอลัมน์เดียวกับผลลัพธ์ จึงเลื่อนไปพร้อมหน้าเว็บแทน */
  .cpu-list {
    margin: 0;
    padding: 6px 0 8px;
    overflow: visible;
  }

  .surface {
    order: 3;
  }

  .site-footer {
    order: 4;
  }

  .backdrop-sun,
  .backdrop-cpu.is-main {
    left: 50%;
  }

  .backdrop-ember {
    width: 420px;
    height: 420px;
    margin: -210px 0 0 -210px;
  }

  .backdrop-ember.is-left {
    left: 8vw;
  }

  .backdrop-cpu.is-main {
    top: 70vh;
    width: 120vw;
    height: 120vw;
    margin: -60vw 0 0 -60vw;
  }

  .backdrop-cpu.is-corner {
    display: none;
  }
}

@media (max-width: 760px) {
  .modal-facts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .modal-fact:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .formula-list {
    grid-template-columns: minmax(0, 1fr);
  }

  .bar-group {
    grid-template-columns: minmax(0, 1fr);
  }

  .bar-group-label,
  .bar-group.is-triple .bar-group-label {
    grid-row: auto;
  }
}

/* มือถือ */
@media (max-width: 600px) {
  /* การ์ด CPU: ป้ายสถานะลงไปอยู่ใต้ชื่อ (ด้านขวาเหลือที่ไม่พอ ข้อความจะถูกบีบ) */
  .cpu-card {
    grid-template-columns: 40px minmax(0, 1fr);
    grid-template-areas:
      "icon text"
      "icon status";
    row-gap: 8px;
  }

  .cpu-card-status {
    justify-self: start;
  }

  .hero {
    padding-top: 60px;
  }

  .hero-subtitle {
    font-size: 0.96rem;
  }

  .sidebar {
    padding: 18px 12px 12px;
    border-radius: 22px;
  }

  .surface {
    gap: 18px;
    padding: 14px;
    border-radius: 22px;
  }

  .card {
    padding: 18px;
  }

  .results-head {
    flex-direction: column;
    align-items: stretch;
  }

  .results-actions {
    flex-wrap: nowrap;
  }

  .view-tabs {
    display: flex;
    flex: 1;
  }

  .view-tab {
    flex: 1 0 auto;
    padding: 7px 12px;
  }

  .algorithm-info .button {
    width: 100%;
  }

  .kpi-card {
    padding: 18px 16px 16px;
  }

  /* ไอคอนอยู่เหนือชื่อค่า ชื่อจึงได้ความกว้างเต็มการ์ด (ถ้าวางข้างกัน ชื่อจะถูกบีบจนตกบรรทัดทีละคำ) */
  .kpi-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  /* กราฟจิ๋วอยู่ใต้ตัวเลข (การ์ดแคบ วางข้างกันแล้วกราฟล้นขอบการ์ด) */
  .kpi-body {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .kpi-chart {
    max-width: none;
  }

  .kpi-strip {
    align-self: stretch; /* ถ้ากึ่งกลาง แถบจะกว้างตามจำนวนช่วงจนล้นการ์ด ยืดเต็มแล้วส่วนเกินถูกตัดในกรอบ */
  }

  .kpi-value {
    font-size: 1.8rem;
  }

  .formula-summary {
    padding: 18px;
  }

  .formula-body {
    padding: 4px 18px 18px;
  }

  th,
  td {
    padding: 11px 14px;
  }

  .bar-row {
    grid-template-columns: 56px 1fr minmax(84px, auto);
  }

  .modal-panel {
    padding: 22px 18px;
    border-radius: 24px;
  }

  .modal-title {
    font-size: 1.35rem;
  }

  .rename-row {
    flex-direction: column;
  }

  .settings-row {
    flex-wrap: wrap;
  }
}

/* เครื่องที่ตั้งค่า "ลดการเคลื่อนไหว": ปิด animation และ transition ทั้งหมด */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after,
  .modal::backdrop {
    animation-duration: 0.001ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
