:root {
  --color-primary: hsl(218, 75%, 50%);
  --color-primary-pressed: hsl(218, 75%, 42%);
  --color-primary-active: hsl(218, 75%, 35%);
  --color-on-primary: #ffffff;

  --color-panel-sidebar: hsl(200, 8%, 13%);
  --color-panel-header: hsl(200, 8%, 11%);
  --color-panel-properties: hsl(200, 8%, 98%);
  --color-canvas-dark: hsl(200, 8%, 10%);
  --color-canvas-light: hsl(200, 8%, 98%);
  --color-border-panel: hsl(200, 8%, 18%);
  --color-border-default: hsl(200, 8%, 88%);
  --color-surface-row: hsl(200, 5%, 96%);
  --color-surface-row-hover: hsl(218, 30%, 94%);
  --color-text-primary: hsl(200, 8%, 12%);
  --color-text-secondary: hsl(200, 8%, 40%);
  --color-text-disabled: hsl(200, 8%, 65%);
  --color-text-on-dark: #ffffff;
  --color-text-on-dark-mute: rgba(255,255,255,0.65);

  /* ── Depth & shape tokens (2026-08-24 demo polish) — ใช้ชุดเดียวกันทุกแท็บ
     เงาเบา 2 ชั้นแทนขอบแข็งเดี่ยวๆ ให้การ์ดมีมิติโดยไม่ฟุ้ง (blur ≤ 12px เสมอ) ── */
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-raised: 0 2px 4px rgba(16, 24, 40, 0.05), 0 6px 12px rgba(16, 24, 40, 0.08);
  --radius-card: 12px;
  --radius-control: 8px;
  --color-border-soft: hsl(200, 12%, 91%);
  --focus-ring: 0 0 0 3px hsla(218, 75%, 50%, 0.22);

  --shell-height-topbar: 52px;
  --shell-height-statusbar: 28px;
  /* ปุ่ม 📋/📐 ย้ายขึ้น topbar แล้ว (2026-08-26) — เหลือแค่ .rail-flyout ที่ยังลอยทับ canvas */
  --rail-flyout-width: 280px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  font-family: 'Anuphan', 'Sarabun', sans-serif;
  color: var(--color-text-primary);
  /* เดิม --color-panel-header (พื้นเข้ม) — topbar เปลี่ยนเป็นกระจกสว่างแล้ว ขอบ letterbox
     ตอนหน้าจอแคบกว่า 1280px จึงควรเป็นโทนอ่อนให้เข้ากับธีมทั้งแอปแทน ไม่ใช่แถบดำโผล่ */
  background: var(--color-canvas-light);
}

body {
  min-width: 1280px;
}

.shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  /* width:100% (ไม่ใช่ 100vw) — .shell เป็นลูกตรงของ body ต้องยึด box ของ body
     ซึ่งมี min-width:1280px อยู่แล้ว ถ้าใช้ 100vw จะยึด viewport ดิบแทน ทำให้จอที่แคบกว่า
     1280px (เช่น browser ย่อ/จอเล็ก) บีบทุกอย่างข้างในจนทับกัน (tabs/ปุ่มใน topbar ซ้อนกัน)
     แทนที่จะ scroll แนวนอนตามที่ body ตั้งใจไว้ */
  width: 100%;
}

/* Topbar restyled 2026-08-27 จากพื้นเข้ม (--color-panel-header) เป็นกระจกสว่าง (glass) ตาม
   moodboard — โทนพื้นทั้งชุดใน moodboard เป็น canvas/tone/surface สีขาว-เกือบขาวหมด (ไม่มีพื้นเข้ม
   เลยนอกจาก toast) การให้ topbar ยังเข้มแบบเดิมมันเลยดู "หลุดโทน" จากทั้งแอป — ใช้พื้นขาวโปร่งแสง
   + backdrop-blur ให้มีมิติลอยเหนือ canvas นิดๆ (สาย glass ที่ user ขอ) แทนแผ่นทึบ */
.topbar {
  height: var(--shell-height-topbar);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  border-bottom: 1px solid var(--color-border-default);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  display: flex;
  align-items: center;
  padding: 0 16px;
  color: var(--color-text-primary);
  font-size: 14px;
  font-weight: 600;
  gap: 4px;
  position: relative;
  z-index: 50;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.topbar__brand-logo {
  height: 28px;
  width: auto;
  display: block;
  color: var(--color-text-primary);
}

/* ไอคอน Lucide ในแถบบน/เมนู — stroke ตาม currentColor เสมอ */
.tb-ic {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

/* thin separators group brand | project | tabs | right-side actions without extra chrome */
.topbar__divider {
  width: 1px;
  height: 22px;
  background: var(--color-border-default);
  flex: 0 0 auto;
  margin: 0 10px;
}

.topbar__project {
  position: relative;
  margin-left: 4px;
  flex: 0 0 auto;
}

.topbar__project-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--color-text-primary);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  max-width: 280px;
}

.topbar__project-trigger:hover {
  background: var(--color-surface-row-hover);
}

.topbar__project-name {
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

/* ป้ายโปรเจกต์ตัวอย่าง — แยกจากชื่อ ไม่โดน ellipsis ตัด (แทน 🧪 เดิม) */
.topbar__project-badge {
  flex: 0 0 auto;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--color-border-default);
  color: var(--color-text-secondary);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.topbar__project-chevron {
  width: 13px;
  height: 13px;
  color: var(--color-text-secondary);
  flex: 0 0 auto;
}

/* เข้าฉากด้วย scale+fade จาก anchor (motion vocabulary: popover/dropdown/menu) — .is-open
   เติมโดย openMenuAnimated() (shell-index.js) หนึ่งเฟรมหลังเอา [hidden] ออก */
.topbar__project-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 280px;
  max-width: 360px;
  background: #fff;
  color: var(--color-text-primary);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  padding: 6px;
  z-index: 200;
  opacity: 0;
  transform: scale(.96) translateY(-6px);
  transform-origin: top left;
  transition: opacity 0.15s cubic-bezier(.2,.8,.2,1), transform 0.15s cubic-bezier(.2,.8,.2,1);
}
.topbar__project-menu.is-open { opacity: 1; transform: scale(1) translateY(0); }
.topbar__project-menu .topbar__project-menu-item {
  opacity: 0; transform: translateY(6px); transition: opacity .18s ease, transform .18s ease;
}
.topbar__project-menu.is-open .topbar__project-menu-item { opacity: 1; transform: none; }
.topbar__project-menu.is-open .topbar__project-list .topbar__project-menu-item:nth-child(1) { transition-delay: .02s; }
.topbar__project-menu.is-open .topbar__project-list .topbar__project-menu-item:nth-child(2) { transition-delay: .06s; }
.topbar__project-menu.is-open .topbar__project-list .topbar__project-menu-item:nth-child(3) { transition-delay: .1s; }
.topbar__project-menu.is-open .topbar__project-list .topbar__project-menu-item:nth-child(4) { transition-delay: .14s; }
.topbar__project-menu.is-open .topbar__project-list .topbar__project-menu-item:nth-child(n+5) { transition-delay: .16s; }

.topbar__project-list {
  max-height: 280px;
  overflow-y: auto;
}

.topbar__project-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--color-text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
}

.topbar__project-menu-item:hover {
  background: var(--color-surface-row-hover);
}

.topbar__project-menu-item--active {
  background: var(--color-surface-row);
  font-weight: 700;
}

.topbar__project-menu-item--new {
  color: var(--color-primary);
  font-weight: 700;
}

.topbar__project-menu-item--demo::after {
  content: ' (ตัวอย่าง)';
  color: var(--color-text-secondary);
  font-weight: 400;
}

.topbar__project-menu-divider {
  height: 1px;
  background: var(--color-border-default);
  margin: 6px 4px;
}

/* ── Topbar right-side action cluster: squeezed icon-only triggers (price, status)
   that reveal their full content on hover/click — same disclosure pattern used
   throughout the shell (project switcher, tab groups) via wireHoverMenu() ── */
.topbar__right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 12px;
  flex: 0 0 auto;
}

/* shared icon-only trigger — status button */
.topbar__icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid var(--color-border-default);
  color: var(--color-text-primary);
  font-size: 15px;
  cursor: pointer;
  padding: 0;
  border-radius: 6px;
  transition: background 0.15s ease;
}

.topbar__icon-btn:hover {
  background: var(--color-surface-row-hover);
}

.topbar__calc-status {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-secondary);
  max-width: 150px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar__calc-status:empty { display: none; }

/* ปุ่มคำนวณ 3 สถานะ (data-state, ตั้งโดย updateHeaderState() ใน shell-index.js):
   never_run = สีหลักเด่น ("คำนวณโปรเจกต์") · stale = เหลืองเตือน ("ข้อมูลเปลี่ยน · คำนวณใหม่",
   ดูดหน้าที่ของ stale banner เดิมมาไว้ที่ปุ่มเดียว) · current = ghost เงียบๆ ("คำนวณใหม่") */
.topbar__calc-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: var(--color-primary);
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.topbar__calc-ic {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
}

/* ยังไม่เคยคำนวณ — ไอคอน "คำนวณซ้ำ" ยังไม่สื่อ ซ่อนไว้ */
.topbar__calc-btn[data-state="never_run"] .topbar__calc-ic {
  display: none;
}

.topbar__calc-btn[data-state="stale"] {
  background: hsl(38, 92%, 55%);
  color: hsl(28, 80%, 16%);
}

.topbar__calc-btn[data-state="current"] {
  background: transparent;
  border-color: var(--color-border-default);
  color: var(--color-text-secondary);
  font-weight: 600;
}

.topbar__calc-btn[data-state="current"]:hover {
  background: var(--color-surface-row-hover);
  color: var(--color-text-primary);
}

.topbar__calc-btn:hover {
  opacity: 0.9;
}

.topbar__calc-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* ── Page header badge — ชื่อ+คำอธิบายของแท็บที่กำลังเปิด ย้ายมาจาก .fp-header เดิม
   ที่เคยวาดซ้ำในเนื้อหาแต่ละโมดูล เดิมเคยเป็นแถบขาวเต็มความกว้างใต้ topbar
   (กินพื้นที่แนวตั้งไปเปล่าๆ ทั้งที่มีแค่ไอคอน+ข้อความสั้นๆ) — ย่อเหลือแค่ป้ายสี่เหลี่ยม
   ลอยอยู่มุมขวาบนของ canvas แทน โฮเวอร์ (หรือโฟกัสด้วยคีย์บอร์ด) เพื่อดูชื่อเต็ม+คำอธิบาย
   (ณ ตอนนี้มีแค่ Overview ที่เรียกใช้ — โมดูลอื่นยังใช้ .fp-header เดิมในเนื้อหา
   จนกว่าจะทยอยย้าย — setActiveTab() ซ่อนป้ายนี้ทุกครั้งที่สลับแท็บ ให้โมดูลที่ใช้
   งานนี้เรียก constistant_setPageHeader() ใหม่เองตอน render) ── */
.page-header-bar {
  position: absolute;
  top: 12px;
  right: 16px;
  z-index: 20;
}

/* [hidden] มี specificity เท่ากับ .page-header-bar (0,1,0) — ต้องระบุ override ตรงๆ
   ไม่งั้น position:absolute ด้านบนชนะ [hidden]{display:none} ของ UA stylesheet เสมอ */
.page-header-bar[hidden] {
  display: none;
}

.page-header-bar__badge {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--color-border-default);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-header-bar__icon {
  font-size: 16px;
}

.page-header-bar__popover {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  min-width: 240px;
  max-width: 360px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
  padding: 12px 14px;
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.page-header-bar:hover .page-header-bar__popover,
.page-header-bar:focus-within .page-header-bar__popover {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.page-header-bar__title {
  font-family: 'Anuphan', sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text-primary);
}

.page-header-bar__subtitle {
  font-size: 12.5px;
  color: var(--color-text-secondary);
  margin-top: 4px;
  line-height: 1.4;
}

.tabs {
  display: flex;
  gap: 14px;
  align-items: center;
  height: 100%;
  margin-right: auto;
  flex-shrink: 0;
}

.tab {
  position: relative;
  padding: 0 6px;
  height: 100%;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--color-text-secondary);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.tab--active {
  color: var(--color-text-primary);
}

.tab--active::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--color-primary);
}

.tab-group {
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
}

.tab-group__trigger {
  background: none;
  border: none;
  color: var(--color-text-secondary);
  font-size: 13px;
  font-weight: 500;
  height: 100%;
  cursor: pointer;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  white-space: nowrap;
}

.tab-group__chevron {
  width: 11px;
  height: 11px;
  opacity: 0.7;
  flex: 0 0 auto;
}

/* ── ชิปหมายเลขเฟส — เป็นทั้งลำดับขั้นและจุดสถานะในตัวเดียว (data-state ตั้งโดย
   updateHeaderState()): empty = เส้นขอบจางๆ · partial = เหลืองอำพัน · done = เขียว + ✓ ── */
.tab-group__chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--color-border-default);
  color: var(--color-text-secondary);
  font-size: 10.5px;
  font-weight: 700;
  flex: 0 0 auto;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.tab-group__chip-check {
  display: none;
  width: 10px;
  height: 10px;
}

.tab-group__chip[data-state="partial"] {
  border-color: hsl(38, 92%, 55%);
  background: hsla(38, 92%, 55%, 0.16);
  color: hsl(38, 92%, 62%);
}

.tab-group__chip[data-state="done"] {
  border-color: transparent;
  background: hsl(145, 55%, 42%);
  color: #fff;
}

.tab-group__chip[data-state="done"] .tab-group__chip-num {
  display: none;
}

.tab-group__chip[data-state="done"] .tab-group__chip-check {
  display: block;
}

.tab-group--active > .tab-group__trigger {
  color: var(--color-text-primary);
}

.tab-group--active::after {
  content: '';
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 0;
  height: 2px;
  background: var(--color-primary);
}

/* เข้าฉากด้วย scale+fade จาก anchor (motion vocabulary: popover/dropdown/menu) — .is-open
   เติมโดย openMenuAnimated() (shell-index.js) หนึ่งเฟรมหลังเอา [hidden] ออก */
.tab-group__menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 200px;
  background: #fff;
  color: var(--color-text-primary);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  padding: 6px;
  z-index: 200;
  opacity: 0;
  transform: scale(.96) translateY(-6px);
  transform-origin: top left;
  transition: opacity 0.15s cubic-bezier(.2,.8,.2,1), transform 0.15s cubic-bezier(.2,.8,.2,1);
}
.tab-group__menu.is-open { opacity: 1; transform: scale(1) translateY(0); }
.tab-group__menu .tab-group__item {
  opacity: 0; transform: translateY(6px); transition: opacity .18s ease, transform .18s ease;
}
.tab-group__menu.is-open .tab-group__item { opacity: 1; transform: none; }
.tab-group__menu.is-open .tab-group__item:nth-child(1) { transition-delay: .02s; }
.tab-group__menu.is-open .tab-group__item:nth-child(2) { transition-delay: .06s; }
.tab-group__menu.is-open .tab-group__item:nth-child(3) { transition-delay: .1s; }
.tab-group__menu.is-open .tab-group__item:nth-child(4) { transition-delay: .14s; }
.tab-group__menu.is-open .tab-group__item:nth-child(n+5) { transition-delay: .18s; }

.tab-group__item.tab {
  display: flex;
  align-items: center;
  gap: 9px;
  height: auto;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--color-text-primary);
  white-space: nowrap;
}

.tab-group__item.tab .tb-ic {
  color: var(--color-text-secondary);
}

.tab-group__item.tab:hover .tb-ic,
.tab-group__item.tab--active .tb-ic {
  color: var(--color-primary);
}

.tab-group__item.tab:hover {
  background: var(--color-surface-row-hover);
}

.tab-group__item.tab--active {
  background: var(--color-surface-row);
  font-weight: 700;
}

.tab-group__item.tab--active::after {
  display: none;
}

/* ── เมนูย่อยซ้อนใน dropdown เฟส (2026-08-26) — บาง item (Site Investigate/BOQ/แผนงาน) มี
   "หัวข้อย่อย" ที่ไปตรงจุดได้เลย (โมดูล Site Investigate 8 อัน, มุมมอง BOQ 6 แบบ, view mode ของ
   Planner 4 แบบ) แทนที่จะลงจอดที่หน้าเริ่มต้นเสมอ — hover ตัวหลักแล้ว flyout ที่สองโผล่ทางขวา
   เข้าฉากด้วย motion เดียวกับเมนูหลัก (scale+fade) ผ่าน openMenuAnimated() เหมือนกัน ──*/
.tab-group__subwrap {
  position: relative;
}

.tab-group__subchevron {
  width: 12px;
  height: 12px;
  margin-left: auto;
  padding-left: 6px;
  color: var(--color-text-secondary);
  flex: 0 0 auto;
}

.tab-group__submenu {
  position: absolute;
  top: -6px;
  left: calc(100% + 6px);
  min-width: 220px;
  background: #fff;
  color: var(--color-text-primary);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  padding: 6px;
  z-index: 210;
  opacity: 0;
  transform: scale(.96) translateX(-6px);
  transform-origin: top left;
  transition: opacity 0.15s cubic-bezier(.2,.8,.2,1), transform 0.15s cubic-bezier(.2,.8,.2,1);
}
.tab-group__submenu.is-open { opacity: 1; transform: scale(1) translateX(0); }

.tab-group__subitem {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary);
  text-decoration: none;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .18s ease, transform .18s ease, background .12s ease;
}
.tab-group__submenu.is-open .tab-group__subitem { opacity: 1; transform: none; }
.tab-group__submenu.is-open .tab-group__subitem:nth-child(1) { transition-delay: .02s; }
.tab-group__submenu.is-open .tab-group__subitem:nth-child(2) { transition-delay: .05s; }
.tab-group__submenu.is-open .tab-group__subitem:nth-child(3) { transition-delay: .08s; }
.tab-group__submenu.is-open .tab-group__subitem:nth-child(4) { transition-delay: .11s; }
.tab-group__submenu.is-open .tab-group__subitem:nth-child(5) { transition-delay: .14s; }
.tab-group__submenu.is-open .tab-group__subitem:nth-child(n+6) { transition-delay: .16s; }

.tab-group__subitem:hover { background: var(--color-surface-row-hover); }

.main {
  /* position: relative — .rail-flyout ลอยทับ canvas โดยอ้างอิงกล่องนี้ */
  position: relative;
  display: flex;
  flex: 1;
  min-height: 0;
}

/* 2026-08-26: ปุ่ม 📋/📐 ย้ายจาก .rail (ลอยทับมุมซ้ายบนของ canvas) ขึ้นไปอยู่ใน topbar
   (.topbar__tools) — canvas จึงกว้างเต็ม 100% ตั้งแต่ใต้ topbar ลงมา ไม่มีอะไรลอยทับอีกต่อไป.
   .rail-flyout ยังเป็นการ์ดลอยเหมือนเดิม แค่เปิดใต้ topbar แทนที่จะเปิดใต้ปุ่มลอย */
.topbar__tools {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 4px;
  flex: 0 0 auto;
}

/* ปุ่มมีทั้งไอคอน+ข้อความ (2026-08-27) — เดิมไอคอนล้วนต้อง hover รอ title tooltip ถึงจะรู้ว่า
   คืออะไร ใส่ label ให้เห็นเลยว่าเป็น "รายละเอียดโครงการ"/"แบบก่อสร้าง" ไม่ต้องเดา */
.rail__btn {
  height: 32px;
  padding: 0 10px 0 8px;
  border-radius: 6px;
  border: 1px solid var(--color-border-default);
  background: transparent;
  color: var(--color-text-primary);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.rail__btn-icon {
  font-size: 15px;
  flex: 0 0 auto;
}

.rail__btn:hover {
  background: var(--color-surface-row-hover);
}

.rail__btn--active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

/* การ์ดลอย ไม่ใช่คอลัมน์เต็มความสูง — เปิดใต้ topbar และสูงเท่าที่เนื้อหาต้องการ (สูงสุดไม่เกิน
   พื้นที่ที่เหลือ) เพื่อไม่ให้กลับไปดูเหมือนแถบข้างเดิม
   Restyled 2026-08-27 เป็นพื้นสว่าง + motion scale-fade เดียวกับ .tab-group__menu/
   .topbar__project-menu (ปุ่ม 📋📐 ย้ายมาอยู่ topbar ข้างเดียวกับเมนูซ้ายแล้ว ดรอปดาวน์จึงควร
   หน้าตา/การเคลื่อนไหวชุดเดียวกัน ไม่ใช่ theme มืดแบบ sidebar เดิม) */
.rail-flyout {
  /* fixed แทน absolute (2026-08-27) — flyout อยู่ใน <main> ห่างจากปุ่ม 📋📐 ที่ย้ายขึ้น topbar
     ไปแล้ว (#topbar-tools) ใน DOM หลายชั้น ancestor ที่ position:relative จึงไม่ใช่ topbar-tools
     ทำให้ left:16px เดิมคำนวณจากขอบซ้ายของ .main แทนที่จะเป็นใต้ปุ่มจริง ๆ (ดรอปดาวน์ไปโผล่มุมซ้าย
     บนของ canvas ทั้งที่ปุ่มอยู่กลาง-ขวา topbar) — ใช้ fixed + จัดตำแหน่งด้วย JS
     (positionRailFlyout ใน shell-index.js) อิง getBoundingClientRect ของปุ่มที่กดจริงแทน */
  position: fixed;
  width: var(--rail-flyout-width, 280px);
  max-height: calc(100vh - var(--shell-height-topbar) - 24px);
  /* .canvas ไม่ได้สร้าง stacking context ของตัวเอง — header ภายในโมดูล (เช่น Drawing
     Intelligence) ใช้ z-index ถึง 100 และจะทับ flyout ถ้าค่านี้ต่ำกว่า จึงตั้ง 150:
     เหนือ chrome ของโมดูล แต่ยังต่ำกว่า modal (250/300) ที่ควรทับ flyout ได้ */
  z-index: 150;
  background: #fff;
  border: 1px solid var(--color-border-default);
  border-radius: 12px;
  color: var(--color-text-primary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: scale(.96) translateY(-6px);
  transform-origin: top left;
  transition: opacity 0.15s cubic-bezier(.2,.8,.2,1), transform 0.15s cubic-bezier(.2,.8,.2,1);
}

.rail-flyout.is-open {
  opacity: 1;
  transform: scale(1) translateY(0);
}

.rail-flyout[hidden] {
  display: none;
}

.rail-flyout__head {
  flex-shrink: 0;
  padding: 12px 10px 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border-default);
}

.rail-flyout__close {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--color-border-default);
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.rail-flyout__close:hover {
  background: var(--color-surface-row-hover);
  color: var(--color-text-primary);
}

.rail-flyout__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
}

.rail-flyout__card {
  border-radius: 8px;
  background: var(--color-surface-row);
  border: 1px solid var(--color-border-default);
  overflow: hidden;
}

.rail-flyout__card[hidden],
.rail-flyout__section[hidden] {
  display: none;
}

/* tooltip แบบ instant (ไม่รอ delay ของ native title) — จัดตำแหน่งด้วย JS เป็น position:fixed
   เพราะ .sidebar/.sidebar__tree มี overflow ที่จะบัง absolute tooltip ไม่ให้โผล่พ้นแถบ */
.hover-tip {
  position: fixed;
  padding: 4px 8px;
  background: hsl(200, 8%, 15%);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  z-index: 500;
  opacity: 0;
  transform: translateY(-50%) translateX(-4px);
  transition: opacity .12s ease, transform .12s ease;
}

.hover-tip--visible {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

.sidebar__tree {
  padding: 0;
  margin: 0;
  list-style: none;
  flex: 0 0 auto;
}

.sidebar__item {
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--color-text-primary);
  font-size: 13px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s ease, color 0.15s ease, padding-left 0.15s ease;
}

.sidebar__item + .sidebar__item {
  margin-top: 4px;
}

.sidebar__item:hover {
  background: var(--color-surface-row-hover);
  color: var(--color-text-primary);
  padding-left: 14px;
}

.sidebar__item--selected {
  background: var(--color-primary);
  color: var(--color-text-on-dark);
  font-weight: 600;
}

.sidebar__item--selected:hover {
  background: var(--color-primary);
  padding-left: 10px;
}

.sidebar__item-icon {
  width: 16px;
  height: 16px;
  border-radius: 2px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: transform 0.15s ease;
}

.sidebar__item:hover .sidebar__item-icon {
  transform: scale(1.15);
}

.sidebar__group-label {
  list-style: none;
  padding: 0 10px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  opacity: 0.85;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar__tree > .sidebar__group-label:first-child {
  padding-top: 0;
}

/* ปุ่ม + ท้ายหัวข้อกลุ่ม "แบบก่อสร้าง" — ทางลัดอัปโหลดแบบเพิ่มที่ยังอยู่แม้มีแบบอยู่แล้ว
   (เดิม CTA แบบเต็ม sidebar__empty-cta โผล่เฉพาะตอนยังไม่มีแบบเลย พอมีแบบแรกแล้ว
   ไม่มีทางอัปโหลดเพิ่มจาก sidebar อีกเลย ต้องไปหาแท็บ Drawing Intelligence เอง) */
.sidebar__group-add {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid var(--color-border-default);
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 13px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 1;
  text-transform: none;
  letter-spacing: normal;
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar__group-add:hover {
  /* แค่ hover ยังไม่ใช่การคลิก — ไม่ต้องเปลี่ยนเป็นสี primary (blue) เต็มๆ แค่สว่างขึ้นเล็กน้อยพอ */
  background: var(--color-surface-row-hover);
  border-color: var(--color-primary);
  color: var(--color-text-primary);
}

.sidebar__empty {
  list-style: none;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar__empty-text {
  font-size: 12px;
  line-height: 1.4;
  color: var(--color-text-secondary);
}

.sidebar__empty-cta {
  align-self: flex-start;
  background: var(--color-surface-row);
  border: 1px solid var(--color-border-default);
  color: var(--color-text-primary);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.sidebar__empty-cta:hover {
  background: var(--color-surface-row-hover);
}

.canvas {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.canvas-panel,
.qt-module {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
}

.canvas-panel.active,
.qt-module.active {
  display: flex;
}

.canvas-panel--dark {
  background: var(--color-canvas-dark);
  color: var(--color-text-on-dark);
  align-items: center;
  justify-content: center;
}

.canvas-panel--light {
  background: var(--color-canvas-light);
  color: var(--color-text-primary);
  align-items: center;
  justify-content: center;
}

.canvas-panel__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
  padding: 32px;
  width: 100%;
  max-width: 520px;
}

.canvas-panel__icon {
  font-size: 56px;
  line-height: 1;
}

.canvas-panel__title {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.3;
  margin: 0;
}

.canvas-panel__description {
  font-size: 15px;
  line-height: 1.4;
  max-width: 460px;
  margin: 0;
}

.qt-module {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  flex-direction: column;
  overflow: auto;
  background: var(--color-canvas-light);
}

.properties__body {
  padding: 14px;
  color: var(--color-text-primary);
  font-size: 13px;
  line-height: 1.5;
}

.properties__field {
  margin-bottom: 16px;
}

.properties__field-label {
  display: block;
  color: var(--color-text-secondary);
  font-size: 12px;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 700;
}

.properties__field-value {
  background: var(--color-surface-row);
  border: 1px solid var(--color-border-default);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--color-text-primary);
  font-weight: 500;
}

.statusbar {
  height: var(--shell-height-statusbar);
  background: var(--color-panel-header);
  border-top: 1px solid var(--color-border-panel);
  display: flex;
  align-items: center;
  padding: 0 16px;
  color: var(--color-text-on-dark-mute);
  font-size: 12px;
}

.statusbar__tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  background: rgba(255,255,255,0.08);
  border-radius: 999px;
  color: var(--color-text-on-dark);
  font-weight: 600;
  margin-left: auto;
}

/* ─────────────────────────────────────────────
   Project Status — compact button in topbar next to "Calculate Project";
   hovering reveals a popover with the "5-second answer" (phase · RAG · overall % · dates · weather),
   rows fading in sequentially. Replaces the old always-visible full-width strip.
   ───────────────────────────────────────────── */
.topbar__status {
  position: relative;
}

/* จุด RAG วาดด้วย CSS (data-rag ตั้งโดย project-status-strip.js) — เลิกใช้ emoji 🟢🟡🔴 */
.topbar__status-dot {
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-border-default);
}

.topbar__status-dot[data-rag="green"] { background: hsl(145, 55%, 48%); box-shadow: 0 0 6px hsla(145, 55%, 48%, 0.6); }
.topbar__status-dot[data-rag="amber"] { background: hsl(38, 92%, 55%); box-shadow: 0 0 6px hsla(38, 92%, 55%, 0.6); }
.topbar__status-dot[data-rag="red"]   { background: hsl(0, 72%, 55%); box-shadow: 0 0 6px hsla(0, 72%, 55%, 0.6); }

/* เข้าฉากด้วย scale+fade จาก anchor (motion vocabulary เดียวกับ Overview's popover/dialog —
   design/handoff/moodboard-motion-manifesto.dc.html) แทน translateY เดิม
   ที่ไม่มี scale — ให้ dropdown ทุกตัวใน topbar เข้าฉากแบบเดียวกันหมด */
.topbar__status-popover {
  position: absolute;
  top: 100%;
  right: 0; /* anchor to the button's right edge — it now sits close to the viewport edge */
  padding-top: 10px; /* เชื่อม hover area กับปุ่มไม่ให้มีช่องว่างที่ทำให้ popover ปิดก่อนเมาส์เข้าถึง */
  width: 260px;
  z-index: 250;
  opacity: 0;
  transform: scale(.96) translateY(-6px);
  transform-origin: top right;
  pointer-events: none;
  transition: opacity 0.15s cubic-bezier(.2,.8,.2,1), transform 0.15s cubic-bezier(.2,.8,.2,1);
}

.topbar__status-popover:empty {
  display: none;
}

.topbar__status:hover .topbar__status-popover,
.topbar__status--open .topbar__status-popover {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

/* ── ป็อปโอเวอร์สถานะ — ตัดให้เหลือแค่สิ่งที่ยัง "ดูเร็วๆ ไม่ต้องเปิด Overview" ได้จริง
      (2026-08-26: ชื่อ/ที่ตั้ง/แถบ progress/วันที่/ฝน ย้ายไปโชว์ครบกว่าใน Overview's widgets แล้ว
      เก็บไว้ซ้ำสองที่ไม่มีประโยชน์ — เหลือ RAG + จำนวนค้าง + งานตอนนี้ + ลิงก์ไป Overview) ── */
.pss-pop {
  background: var(--color-panel-properties, #fff);
  color: var(--color-text-primary);
  font-family: 'Anuphan', sans-serif;
  border-radius: 12px;
  border-left: 4px solid var(--color-text-disabled);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  padding: 12px 14px;
}
.pss-pop--green { border-left-color: hsl(145, 63%, 42%); }
.pss-pop--amber { border-left-color: hsl(38, 92%, 50%); }
.pss-pop--red   { border-left-color: hsl(0, 72%, 51%); }

.pss-pop__row {
  opacity: 0;
  transform: translateX(8px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.pss-pop__row + .pss-pop__row {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--color-border-default);
}

.topbar__status:hover .pss-pop__row:nth-child(1), .topbar__status--open .pss-pop__row:nth-child(1) { opacity: 1; transform: none; transition-delay: .02s; }
.topbar__status:hover .pss-pop__row:nth-child(2), .topbar__status--open .pss-pop__row:nth-child(2) { opacity: 1; transform: none; transition-delay: .07s; }

.pss-pop__sub { font-size: 11px; color: var(--color-text-secondary); margin-top: 2px; }

.pss-pop__rag { display: flex; align-items: center; gap: 8px; }
.pss-pop__rag-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-border-default);
  flex: 0 0 auto;
}
.pss-pop__rag-dot[data-rag="green"] { background: hsl(145, 55%, 42%); }
.pss-pop__rag-dot[data-rag="amber"] { background: hsl(38, 92%, 50%); }
.pss-pop__rag-dot[data-rag="red"]   { background: hsl(0, 72%, 50%); }
.pss-pop__rag-label { font-size: 13px; font-weight: 700; }

.pss-pop__link {
  display: block; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--color-border-default);
  font-size: 12px; font-weight: 600; color: var(--color-primary); text-decoration: none;
  opacity: 0; transform: translateX(8px); transition: opacity 0.22s ease, transform 0.22s ease, color .12s ease;
}
.pss-pop__link:hover { color: var(--color-primary-pressed); text-decoration: underline; }
.topbar__status:hover .pss-pop__link, .topbar__status--open .pss-pop__link { opacity: 1; transform: none; transition-delay: .12s; }

/* ── Pipeline result toast — สรุปผลหลังกด Calculate Project ─────────────── */
.pipeline-toast {
  position: fixed;
  top: calc(var(--shell-height-topbar) + 12px);
  right: 16px;
  width: 320px;
  background: #fff;
  color: var(--color-text-primary);
  font-family: 'Anuphan', sans-serif;
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  padding: 14px 16px;
  z-index: 300; /* เหนือ popover (250) ใต้ไม่มีอะไรบัง */
  animation: pipeline-toast-in .22s ease-out both;
}
.pipeline-toast--leaving { opacity: 0; transform: translateY(-6px); transition: opacity .35s ease, transform .35s ease; }
@keyframes pipeline-toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .pipeline-toast { animation: none; }
  .pipeline-toast--leaving { transition: opacity .35s ease; transform: none; }
  .topbar__project-menu, .tab-group__menu, .topbar__status-popover, .tab-group__submenu,
  .topbar__project-menu-item, .tab-group__item, .tab-group__subitem, .pss-pop__row, .pss-pop__link,
  .rail-flyout, .sidebar__item {
    transition: none !important;
  }
}
.pipeline-toast__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.pipeline-toast__title { font-size: 14px; font-weight: 700; }
.pipeline-toast__close {
  background: none; border: none; cursor: pointer; color: var(--color-text-secondary);
  font-size: 13px; padding: 2px 6px; border-radius: 4px;
}
.pipeline-toast__close:hover { background: var(--color-surface-row); }
.pipeline-toast__rows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.pipeline-toast__row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.pipeline-toast__row span { color: var(--color-text-secondary); }
.pipeline-toast__row b { font-family: 'JetBrains Mono', monospace; font-weight: 600; white-space: nowrap; }

.pipeline-toast__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pipeline-toast__actions button,
.pipeline-toast__actions a {
  font-family: 'Anuphan', sans-serif; font-size: 12px; font-weight: 600;
  color: var(--color-primary); background: transparent;
  border: 1px solid var(--color-border-default); border-radius: 6px;
  padding: 5px 10px; cursor: pointer; text-decoration: none;
  transition: background .15s ease, border-color .15s ease;
}
.pipeline-toast__actions button:hover,
.pipeline-toast__actions a:hover { background: var(--color-surface-row-hover); border-color: var(--color-primary); }

/* ── Profile chip in topbar (js/shell/profile-chip.js) ─────────────────── */
.pp-chip { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px;
  border: 1px solid var(--color-border, #e2e8f0); border-radius: 999px; background: none;
  cursor: pointer; transition: background .15s ease, border-color .15s ease; }
.pp-chip:hover { background: var(--color-surface-row-hover, #f1f5f9); border-color: #94a3b8; }
/* #1a4080 = ค่าเดียวกับที่ handle_new_user() เขียนลง profiles.avatar_color ตอนสมัคร
   (supabase/migrations/20260729000001_real_per_user_auth.sql) — ที่เดียวที่ยังใช้สีนั้นอยู่ */
.pp-chip__avatar { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: #1a4080; color: #fff; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.pp-chip__avatar--empty { background: #cbd5e1; color: #475569; }
/* ชิปนี้อยู่ในคลัสเตอร์ขวาของ topbar ที่กว้างจำกัด (ดู .tabs overflow:hidden ด้านบน) —
   เคยตั้งไว้ 72px สมัยที่แสดง "ชื่อโปรไฟล์" ภาษาไทยสั้นๆ แต่ตอนนี้แสดงอีเมลจริง
   ซึ่งถูกตัดจนอ่านไม่ออก จึงขยายเป็น 160px (ตรวจแล้วที่ 1280px ไม่ทับ nav) —
   อีเมลเต็มยังดูได้จาก title ของปุ่ม */
.pp-chip__name { font-size: 13px; color: #334155; max-width: 160px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.pp-chip--empty .pp-chip__name { color: #64748b; }
