/* ===== fonts (local, ใช้ได้แบบออฟไลน์) ===== */
@font-face { font-family: 'Plex Thai'; src: url('../fonts/ibm-plex-sans-thai-thai-400-normal.woff2') format('woff2'); font-weight: 400; unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Plex Thai'; src: url('../fonts/ibm-plex-sans-thai-thai-500-normal.woff2') format('woff2'); font-weight: 500; unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Plex Thai'; src: url('../fonts/ibm-plex-sans-thai-thai-600-normal.woff2') format('woff2'); font-weight: 600; unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Plex Thai'; src: url('../fonts/ibm-plex-sans-thai-thai-700-normal.woff2') format('woff2'); font-weight: 700; unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Plex Thai'; src: url('../fonts/ibm-plex-sans-thai-latin-400-normal.woff2') format('woff2'); font-weight: 400; unicode-range: U+0000-00FF, U+2000-206F, U+2190-22FF; }
@font-face { font-family: 'Plex Thai'; src: url('../fonts/ibm-plex-sans-thai-latin-500-normal.woff2') format('woff2'); font-weight: 500; unicode-range: U+0000-00FF, U+2000-206F, U+2190-22FF; }
@font-face { font-family: 'Plex Thai'; src: url('../fonts/ibm-plex-sans-thai-latin-600-normal.woff2') format('woff2'); font-weight: 600; unicode-range: U+0000-00FF, U+2000-206F, U+2190-22FF; }
@font-face { font-family: 'Plex Thai'; src: url('../fonts/ibm-plex-sans-thai-latin-700-normal.woff2') format('woff2'); font-weight: 700; unicode-range: U+0000-00FF, U+2000-206F, U+2190-22FF; }
@font-face { font-family: 'Plex Mono'; src: url('../fonts/ibm-plex-mono-latin-400-normal.woff2') format('woff2'); font-weight: 400; }
@font-face { font-family: 'Plex Mono'; src: url('../fonts/ibm-plex-mono-latin-500-normal.woff2') format('woff2'); font-weight: 500; }
@font-face { font-family: 'Plex Mono'; src: url('../fonts/ibm-plex-mono-latin-600-normal.woff2') format('woff2'); font-weight: 600; }

:root {
  --paper: #f2eee4;
  --paper-2: #e9e3d5;
  --card: #fbf9f4;
  --ink: #1d262f;
  --ink-fill: #1d262f;       /* ใช้เป็นสีพื้น (ปุ่มเข้ม/แถบ) — ธีมมืดเปลี่ยนเป็นเทาเข้มเพื่อให้ตัวอักษรขาวยังอ่านได้ */
  --surface: #fff;           /* พื้นช่องกรอก/การ์ดย่อย */
  --tint-th: #f6f2ea; --tint-head: #efeae0; --tint-hover: #fffaf0; --tint-blue: #f3f8fc; --tint-ok: #e5f2e6; --tint-warm: #fff1e6;   /* พื้นอ่อนของหัวตาราง/แถวเมื่อชี้/สถานะ — ธีมมืดเปลี่ยนเป็นเฉดมืด */
  --warn-ink: #7a5200; --warn-bg: #fbecc4; --warn-line: #ecd28d; --ok-ink: #1f6130; --ok-bg: #dcefdd; --ok-line: #b4d8b8;
  --ink-2: #4f5b66;
  --ink-3: #566370;
  --line: #d6cdbb;
  --line-2: #c3b8a2;
  --accent: #d24a0f;        /* ส้มเตือน แบบสติกเกอร์บนตู้ไฟ */
  --accent-soft: #f6dccd;
  --blue: #1f5d94;          /* หมึกแบบพิมพ์เขียว */
  --blue-soft: #dbe6ef;
  --ok: #2f7d3b;
  --bad: #b3261e;
  --bad-soft: #f4d9d6;
  --phA: #8a5528;           /* L1 น้ำตาล */
  --phB: #26292d;           /* L2 ดำ */
  --phC: #6f757c;           /* L3 เทา */
  --phN: #2e66c7;
  --radius: 6px;
  --shadow: 0 1px 0 rgba(29, 38, 47, .06), 0 6px 18px -10px rgba(29, 38, 47, .25);
  --mono: 'Plex Mono', ui-monospace, Consolas, monospace;
  --sans: 'Plex Thai', 'Leelawadee UI', Tahoma, sans-serif;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --z-tabs: 25; --z-topbar: 30; --z-scrim: 50; --z-drawer: 60; --z-importer: 65; --z-modal: 90; --z-toast: 95; --z-pop: 100; --z-drop: 120; --z-ghost: 200;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.55 var(--sans);
  color: var(--ink);
  background: var(--paper);
  background-image:
    linear-gradient(rgba(31, 93, 148, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 93, 148, .045) 1px, transparent 1px);
  background-size: 24px 24px;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.tiny { font-size: 12px; }
.hidden { display: none !important; }

/* ===== top bar ===== */
.topbar {
  position: sticky; top: 0; z-index: var(--z-topbar);
  display: flex; align-items: center; gap: 18px;
  padding: 10px 20px;
  background: var(--ink-fill);
  color: #efe9dc;
  border-bottom: 3px solid var(--accent);
}
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand svg { width: 30px; height: 30px; }
.brand b { font-weight: 600; letter-spacing: .2px; }
.brand small { display: block; font-size: 11px; color: #a9b1b8; letter-spacing: .6px; text-transform: uppercase; font-family: var(--mono); }
.proj-name {
  background: transparent; border: 1px dashed transparent; color: #fff; padding: 4px 8px; border-radius: 4px;
  min-width: 220px; font-weight: 500;
}
.proj-name:hover, .proj-name:focus { border-color: #5d6a76; outline: none; }
.calc-chip {
  display: inline-flex; align-items: center; gap: 6px; font: 12px var(--mono); color: #b9c2ca;
  padding: 3px 8px; border: 1px solid #39444f; border-radius: 99px;
}
.calc-chip i { width: 7px; height: 7px; border-radius: 50%; background: #5ec26a; box-shadow: 0 0 0 0 rgba(94, 194, 106, .7); }
.calc-chip.busy i { background: #f0b429; animation: pulse 1s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(240, 180, 41, .7); } 70% { box-shadow: 0 0 0 7px rgba(240, 180, 41, 0); } 100% { box-shadow: 0 0 0 0 rgba(240, 180, 41, 0); } }
.spacer { flex: 1; }
.tb-btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer; white-space: nowrap;
  background: transparent; color: #e7e1d3; border: 1px solid #45515c; border-radius: 5px; padding: 0 12px; min-height: 36px; line-height: 1;
  transition: background .15s, border-color .15s, transform .15s var(--ease);
}
.tb-btn:hover { background: #2a343e; border-color: #6c7884; }
.tb-btn:active { transform: translateY(1px); }
.tb-btn.primary { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; }
.tb-btn.primary:hover { background: #b93f0b; }
.tb-btn svg { width: 16px; height: 16px; }

/* ===== tabs ===== */
.tabs {
  position: sticky; top: 55px; z-index: var(--z-tabs);
  display: flex; gap: 2px; padding: 0 20px; background: var(--paper-2); border-bottom: 1px solid var(--line-2);
  overflow-x: auto;
}
.tab {
  position: relative; cursor: pointer; border: 0; background: none; padding: 11px 14px 10px; color: var(--ink-2); white-space: nowrap;
}
.tab .no { font: 11px var(--mono); color: var(--ink-3); margin-right: 6px; }
.tab:hover { color: var(--ink); }
.tab.on { color: var(--ink); font-weight: 600; }
.tab.on::after {
  content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 3px; background: var(--ink);
  animation: grow .35s var(--ease);
}
@keyframes grow { from { transform: scaleX(.2); opacity: 0; } to { transform: none; opacity: 1; } }

main { padding: 18px 20px 60px; }
.view { animation: viewIn .35s var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ===== cards / generic ===== */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.card-h h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card-b { padding: 14px; }
.label {
  font: 500 11px var(--mono); letter-spacing: 1.2px; text-transform: uppercase; color: var(--ink-3);
}
.tag { display: inline-block; font: 500 11px var(--mono); padding: 1px 6px; border-radius: 3px; border: 1px solid var(--line-2); color: var(--ink-2); background: #fff8; }
.tag.lp { border-color: #9fb7cd; color: var(--blue); }
.tag.sdb { border-color: #e2ad8f; color: var(--tag-sdb); }
.tag.mdb { border-color: var(--ink); color: #fff; background: var(--ink-fill); }
.tag.em { border-color: var(--bad); color: var(--bad); background: var(--bad-soft); margin-left: 4px; } /* แผงฉุกเฉิน (ATS) */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--line-2); background: var(--surface); border-radius: 5px; padding: 6px 12px; color: var(--ink);
  transition: background .15s, border-color .15s, transform .12s var(--ease), box-shadow .15s;
}
.btn:hover { border-color: var(--ink-2); box-shadow: 0 2px 0 rgba(0, 0, 0, .05); }
.btn:active { transform: translateY(1px); }
.btn.dark { background: var(--ink-fill); color: #fff; border-color: var(--ink); }
.btn.dark:hover { background: #2c3843; }
.btn.accent { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: #0000000a; border-color: transparent; color: var(--ink); }
.btn.sm { padding: 3px 8px; font-size: 12.5px; }
.btn.danger:hover { color: var(--bad); border-color: var(--bad); }
.btn svg { width: 15px; height: 15px; }

input[type=text], input[type=number], input[type=date], select, textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line-2); border-radius: 4px; padding: 6px 9px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(31, 93, 148, .15); }
input[type=number] { font-family: var(--mono); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 12.5px; color: var(--ink-2); }
.field .hint { font-size: 11.5px; color: var(--ink-3); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; margin-bottom: 10px; font-size: 13.5px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 5px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 5px 12px; cursor: pointer; color: var(--ink-2); transition: background .15s; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--ink-fill); color: #fff; }

/* ===== design layout ===== */
.design { display: grid; grid-template-columns: 330px minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
@media (max-width: 1280px) { .design { grid-template-columns: 300px minmax(0, 1fr); } .design .side-r { grid-column: 1 / -1; } }
@media (max-width: 820px) { .design { grid-template-columns: 1fr; } }

/* tree */
.tree { list-style: none; margin: 0; padding: 6px 0; }
.tree ul { list-style: none; margin: 0; padding-left: 16px; border-left: 1px dashed var(--line-2); margin-left: 15px; }
.node {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; margin: 1px 6px; border-radius: 5px; cursor: pointer;
  border: 1px solid transparent; transition: background .15s, border-color .15s;
  animation: nodeIn .3s var(--ease) both;
}
@keyframes nodeIn { from { opacity: 0; transform: translateX(-6px); } to { opacity: 1; transform: none; } }
.node:hover { background: #0000000a; }
.node.on { background: var(--surface); border-color: var(--line-2); box-shadow: inset 3px 0 0 var(--accent); }
.node .nm { font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node .kva { font: 12px var(--mono); color: var(--ink-3); }
.tree-actions { display: flex; gap: 6px; padding: 10px; border-top: 1px dashed var(--line); }
.tree-actions .btn { flex: 1 1 0; justify-content: center; white-space: nowrap; padding-left: 8px; padding-right: 8px; min-width: 0; }

/* board header */
.board-head { display: grid; grid-template-columns: 1.2fr .8fr .8fr .8fr 1fr; gap: 10px; }
@media (max-width: 1100px) { .board-head { grid-template-columns: 1fr 1fr; } }
.board-title { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.board-title input { font-size: 22px; font-weight: 600; border: 0; background: transparent; padding: 0; width: auto; min-width: 120px; }
.board-title input:focus { box-shadow: none; border-bottom: 2px solid var(--blue); border-radius: 0; }

/* device palette */
.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.tile {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; cursor: pointer;
  padding: 10px 11px 9px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; text-align: left;
  transition: transform .2s var(--ease), box-shadow .2s, border-color .2s;
  animation: tileIn .4s var(--ease) both;
}
.tile:nth-child(2) { animation-delay: .03s; } .tile:nth-child(3) { animation-delay: .06s; } .tile:nth-child(4) { animation-delay: .09s; }
.tile:nth-child(5) { animation-delay: .12s; } .tile:nth-child(6) { animation-delay: .15s; } .tile:nth-child(7) { animation-delay: .18s; }
.tile:nth-child(8) { animation-delay: .21s; } .tile:nth-child(9) { animation-delay: .24s; } .tile:nth-child(10) { animation-delay: .27s; }
.tile:nth-child(11) { animation-delay: .30s; }
@keyframes tileIn { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.tile:hover { transform: translateY(-2px); border-color: var(--ink-2); box-shadow: 0 8px 16px -10px rgba(0, 0, 0, .35); }
.tile:active { transform: translateY(0); }
.tile svg { width: 26px; height: 26px; color: var(--ink); stroke-width: 1.6; }
.tile b { font-weight: 500; font-size: 13.5px; }
.tile small { color: var(--ink-3); font-size: 11.5px; line-height: 1.3; }
.tile::after {
  content: '+'; position: absolute; top: 6px; right: 9px; font: 16px var(--mono); color: var(--line-2); transition: color .2s, transform .2s var(--ease);
}
.tile:hover::after { color: var(--accent); transform: rotate(90deg); }

/* item list */
.items { display: flex; flex-direction: column; gap: 6px; }
.item {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) auto auto; gap: 10px; align-items: center;
  padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
  transition: border-color .15s, transform .2s var(--ease), box-shadow .2s;
  animation: itemIn .35s var(--ease) both;
}
@keyframes itemIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.item:hover { border-color: var(--ink-2); box-shadow: 0 4px 12px -8px rgba(0, 0, 0, .35); }
.item .ic { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 5px; background: var(--paper); }
.item .ic svg { width: 20px; height: 20px; }
.item .t b { font-weight: 500; }
.item .t div { font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .va { font: 13px var(--mono); text-align: right; white-space: nowrap; }
.item .va small { display: block; color: var(--ink-3); font-size: 11px; }
.item.removing { animation: itemOut .25s var(--ease) forwards; }
@keyframes itemOut { to { opacity: 0; transform: translateX(16px); height: 0; padding: 0; margin: 0; } }
.empty {
  padding: 26px; text-align: center; color: var(--ink-2); border: 1.5px dashed var(--line-2); border-radius: 6px; background: #fff6;
}
.empty svg { width: 46px; height: 46px; color: var(--line-2); display: block; margin: 0 auto 6px; }

/* right summary */
.side-r { position: sticky; top: 108px; display: flex; flex-direction: column; gap: 12px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.kpi { background: var(--card); padding: 10px 12px; }
.kpi .v { font: 600 20px var(--mono); letter-spacing: -.5px; }
.kpi .v small { font-size: 12px; font-weight: 400; color: var(--ink-3); margin-left: 3px; }
.phasebars { display: flex; flex-direction: column; gap: 7px; }
.pbar { display: grid; grid-template-columns: 18px 1fr 92px; gap: 8px; align-items: center; font-size: 12.5px; }
.pbar .k { font: 600 12px var(--mono); }
.pbar .track { height: 12px; background: repeating-linear-gradient(90deg, #0000000d 0 1px, transparent 1px 10%), var(--paper-2); border-radius: 2px; overflow: hidden; }
.pbar .fill { height: 100%; width: 0; transition: width .7s var(--ease); border-radius: 2px; }
.pbar .v { font: 12px var(--mono); text-align: right; }
.feeder-chip {
  display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 13px; padding: 10px 12px; background: var(--ink-fill); color: #efe9dc; border-radius: 6px;
}
.feeder-chip dt { color: #9aa5af; font-size: 12px; }
.feeder-chip dd { margin: 0; font-family: var(--mono); }
.warns { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.warns li {
  font-size: 12.5px; padding: 6px 9px 6px 26px; background: var(--bad-soft); color: var(--bad-ink); border-radius: 4px; position: relative;
  animation: itemIn .3s var(--ease) both;
}
.warns li::before { content: '!'; position: absolute; left: 8px; top: 5px; width: 13px; height: 13px; border-radius: 50%; background: var(--bad); color: #fff; font: 700 10px/13px var(--mono); text-align: center; }
.okline { font-size: 12.5px; color: var(--ok); display: flex; align-items: center; gap: 6px; }

.mini-sched { width: 100%; border-collapse: collapse; font-size: 12px; }
.mini-sched td { padding: 3px 4px; border-bottom: 1px dotted var(--line); }
.mini-sched td.n { font-family: var(--mono); color: var(--ink-3); width: 26px; }
.mini-sched td.r { text-align: right; font-family: var(--mono); white-space: nowrap; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; vertical-align: middle; margin-right: 4px; }
.dot.A { background: var(--phA); } .dot.B { background: var(--phB); } .dot.C { background: var(--phC); }

/* ===== drawer ===== */
.scrim { position: fixed; inset: 0; background: rgba(20, 26, 32, .28); z-index: var(--z-scrim); opacity: 0; pointer-events: none; transition: opacity .25s; }
.scrim.on { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); z-index: var(--z-drawer); background: var(--card);
  border-left: 1px solid var(--line-2); box-shadow: -20px 0 40px -20px rgba(0, 0, 0, .35);
  transform: translateX(105%); transition: transform .38s var(--ease); display: flex; flex-direction: column;
}
.drawer.on { transform: none; }
.drawer-h { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.drawer-h svg { width: 26px; height: 26px; }
.drawer-h h3 { margin: 0; font-size: 17px; font-weight: 600; flex: 1; }
.drawer-b { flex: 1; overflow: auto; padding: 16px 18px; }
.drawer-b > * { animation: fieldIn .4s var(--ease) both; }
.drawer-b > *:nth-child(2) { animation-delay: .04s; } .drawer-b > *:nth-child(3) { animation-delay: .08s; }
.drawer-b > *:nth-child(4) { animation-delay: .12s; } .drawer-b > *:nth-child(5) { animation-delay: .16s; }
.drawer-b > *:nth-child(6) { animation-delay: .2s; } .drawer-b > *:nth-child(n+7) { animation-delay: .24s; }
@keyframes fieldIn { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
.drawer-f { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--paper); }
.preview {
  margin: 4px 0 14px; padding: 10px 12px; background: var(--blue-soft); border: 1px solid #b9cde0; border-radius: 5px; font-size: 13px; color: #173f63;
}
.preview .num { font-weight: 600; }
.helper { margin: -2px 0 14px; padding: 10px; border: 1px dashed var(--line-2); border-radius: 5px; background: #fff8; }
.helper summary { cursor: pointer; font-size: 12.5px; color: var(--blue); }
.helper[open] summary { margin-bottom: 8px; }

/* ===== schedule (panel) ===== */
.sched-wrap { display: flex; flex-direction: column; gap: 22px; }
.sheet { background: var(--surface); border: 1px solid var(--line-2); box-shadow: var(--shadow); padding: 18px; position: relative; }
.sheet::before, .sheet::after { content: ''; position: absolute; width: 14px; height: 14px; border: 1.5px solid var(--ink-3); }
.sheet::before { top: 6px; left: 6px; border-right: 0; border-bottom: 0; }
.sheet::after { bottom: 6px; right: 6px; border-left: 0; border-top: 0; }
.sheet-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.sheet-tools h3 { margin: 0; font-size: 16px; flex: 1; }
table.ps { width: 100%; border-collapse: collapse; font-size: 11.5px; }
table.ps th, table.ps td { border: 1px solid #b9b2a4; padding: 2px 5px; text-align: center; white-space: nowrap; }
table.ps thead th { background: var(--tint-head); font-weight: 600; font-size: 10.5px; }
table.ps td.l { text-align: left; }
table.ps td.desc { text-align: left; min-width: 120px; }
table.ps tr.space td { color: var(--ink-3); }
table.ps tr.sep td { border-top: 2px solid var(--ink); }
table.ps tr.tot td { background: var(--tint-head); font-weight: 600; }
table.ps td.phA { box-shadow: inset 3px 0 0 var(--phA); }
table.ps td.phB { box-shadow: inset 3px 0 0 var(--phB); }
table.ps td.phC { box-shadow: inset 3px 0 0 var(--phC); }
table.ps .hd td { border: 1px solid #b9b2a4; text-align: left; }
table.ps .hd td b { font-weight: 600; }
table.ps tbody tr { animation: rowIn .3s var(--ease) both; }
@keyframes rowIn { from { opacity: 0; } to { opacity: 1; } }
table.ps td.num, table.ps td.mono { font-family: var(--mono); }
.rcd { font: 600 10.5px var(--mono); color: var(--accent); border: 1px solid var(--accent); border-radius: 2px; padding: 0 2px; margin-left: 3px; }

/* feeder / generic data table */
table.dt { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.dt th, table.dt td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; }
table.dt th { font: 500 12px var(--sans); letter-spacing: 0; text-transform: none; color: var(--ink-2); background: var(--tint-th); border-bottom: 1px solid var(--line-2); }
table.dt td.r, table.dt th.r { text-align: right; }
table.dt td.num { font-family: var(--mono); }
table.dt tbody tr { transition: background .15s; }
table.dt tbody tr:hover { background: var(--tint-hover); }
table.dt tfoot td { font-weight: 600; border-top: 2px solid var(--ink); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 1100px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.bigstats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.bigstat { padding: 14px 16px; background: var(--card); border: 1px solid var(--line); border-radius: 6px; position: relative; overflow: hidden; }
.bigstat .v { font: 600 26px var(--mono); letter-spacing: -1px; margin-top: 2px; }
.bigstat .v small { font-size: 13px; font-weight: 400; color: var(--ink-3); margin-left: 4px; letter-spacing: 0; }
.bigstat .s { font-size: 12px; color: var(--ink-2); }
.bigstat::after { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); transform-origin: top; animation: bar .6s var(--ease) both; }
.bigstat:nth-child(2)::after { background: var(--blue); } .bigstat:nth-child(3)::after { background: var(--ink); } .bigstat:nth-child(4)::after { background: var(--ok); }
@keyframes bar { from { transform: scaleY(0); } to { transform: none; } }

/* steps / method */
.steps { list-style: none; margin: 0; padding: 0; counter-reset: s; }
.steps li { counter-increment: s; position: relative; padding: 6px 0 6px 34px; border-bottom: 1px dotted var(--line); }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 7px; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line-2); font: 11px/20px var(--mono); text-align: center; color: var(--ink-2); background: var(--surface); }
.steps .t { font-weight: 500; }
.steps .f { font-family: var(--mono); font-size: 12.5px; color: var(--formula, #173f63); word-break: break-word; }
.steps .ref { font-size: 11.5px; color: var(--accent); margin-left: 6px; white-space: nowrap; }
details.acc { border: 1px solid var(--line); border-radius: 6px; background: var(--card); margin-bottom: 8px; overflow: hidden; }
details.acc > summary { cursor: pointer; list-style: none; padding: 10px 14px; display: flex; gap: 10px; align-items: center; }
details.acc > summary::-webkit-details-marker { display: none; }
details.acc > summary::before { content: ''; width: 7px; height: 7px; border-right: 1.5px solid var(--ink-2); border-bottom: 1.5px solid var(--ink-2); transform: rotate(-45deg); transition: transform .2s var(--ease); }
details.acc[open] > summary::before { transform: rotate(45deg); }
details.acc > div { padding: 4px 16px 12px; animation: viewIn .3s var(--ease); }
.rules { columns: 2; column-gap: 28px; font-size: 13px; }
.rules li { break-inside: avoid; margin-bottom: 6px; }
@media (max-width: 1000px) { .rules { columns: 1; } }

/* SLD */
.sld-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--line-2); border-radius: 6px; padding: 10px; }
.sld text { font-family: var(--sans); }
.sld .mono { font-family: var(--mono); }
.sld .wire { stroke: var(--ink); stroke-width: 1.4; fill: none; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.2s var(--ease) forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.sld .box { fill: #fff; stroke: var(--ink); stroke-width: 1.3; }
.sld .box.sdb { stroke-dasharray: 5 3; }
/* องค์ประกอบ SLD 12 ส่วน (แผนแม่บท 2.4): เส้นแบ่งเขต/กรอบตู้เป็นเส้นประ (มี attribute กำกับในไฟล์ SVG แล้ว) · เครื่องมือวัด · บล็อกโหลดทึบสีดำ */
.sld .dem, .sld .encl { fill: none; stroke: var(--ink); stroke-width: 1.2; }
.sld .instr { fill: #fff; stroke: var(--ink); stroke-width: 1.2; }
.sld .load-block { fill: #111; stroke: #111; }
.sld .load-block.em { stroke: var(--bad); stroke-width: 2; }
.sld .lb-t { fill: #fff; }
.sld .wire.gnd { stroke-dasharray: none; animation: none; stroke-dashoffset: 0; }
.sld .box.em { stroke: var(--bad); stroke-width: 1.6; }
.sld .wire.em { stroke: var(--bad); stroke-dasharray: none; animation: none; }
.sld .em-t { fill: var(--bad); }
.sld .encl.em { stroke: var(--bad); }
.sld g.n { animation: rowIn .5s var(--ease) both; }

/* toast */
.toasts {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: var(--z-toast);
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; width: min(560px, calc(100vw - 24px));
}
.toast {
  position: relative; overflow: hidden; display: flex; align-items: center; gap: 12px; max-width: 100%;
  background: var(--ink-fill); color: #f1ece2; padding: 10px 16px; border-radius: 8px; font-size: 13.5px; box-shadow: 0 10px 30px -12px rgba(0, 0, 0, .5);
  opacity: 0; transform: translateY(16px) scale(.97); pointer-events: none;
  transition: transform .4s var(--ease), opacity .3s;
}
.toast.on { opacity: 1; transform: none; pointer-events: auto; }
.toast.out { opacity: 0; transform: translateY(-8px) scale(.97); pointer-events: none; }
.toast .msg { min-width: 0; overflow-wrap: anywhere; }
.toast .undo-btn { background: transparent; color: #f6c8a8; border-color: #55606b; flex: none; }
.toast .undo-btn:hover { background: #ffffff14; border-color: #f6c8a8; }
.toast .undo-btn:disabled { opacity: .35; cursor: not-allowed; background: transparent; border-color: #55606b; }
.toast .life { position: absolute; left: 0; bottom: 0; height: 2px; width: 100%; background: var(--accent); transform-origin: left; animation: toastLife linear forwards; opacity: .8; }
@keyframes toastLife { to { transform: scaleX(0); } }

/* settings */
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 16px; align-items: start; }
.settings .card-b h4 { margin: 14px 0 8px; font-size: 13px; color: var(--ink-2); font-weight: 600; }

/* report (สำหรับพิมพ์) */
#report { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}

/* วาดซ้ำในแท็บเดิม: ไม่เล่นแอนิเมชันเข้าซ้ำ ยกเว้นของที่เพิ่งเพิ่ม */
.calm .node:not(.fresh), .calm .item:not(.fresh), .calm .tile, .calm table.ps tbody tr, .calm table.dt tbody tr,
.calm .warns li, .calm .bigstat::after, .calm .sld .wire, .calm .sld g.n { animation: none !important; }
.calm .sld .wire { stroke-dashoffset: 0; }
.calm .item.fresh { animation: itemPop .5s var(--ease) both; }
/* ลบอุปกรณ์: ต้องเล่นแอนิเมชันออกแม้อยู่ใน .calm (ไม่งั้นแถวค้างอยู่ ~230 ms ก่อนหาย) */
.calm .item.removing, .item.removing { animation: itemOut .22s var(--ease) forwards !important; pointer-events: none; }
@keyframes itemPop { 0% { opacity: 0; transform: translateY(-6px) scale(.98); background: var(--accent-soft); } 60% { opacity: 1; transform: none; background: var(--accent-soft); } 100% { background: var(--surface); } }

.topbar .proj-name { background: transparent; color: #fff; border: 1px dashed transparent; font-size: 15px; }
.topbar .proj-name:hover, .topbar .proj-name:focus { border-color: #5d6a76; box-shadow: none; }
.calc-chip { white-space: nowrap; }
.node svg { width: 18px; height: 18px; flex: none; color: var(--ink-2); }
.node.on svg { color: var(--accent); }
.card-h svg, .sheet-tools svg { width: 15px; height: 15px; }
@media (max-width: 1180px) {
  .brand small { display: none; }
  .topbar { gap: 10px; }
  .topbar .proj-name { min-width: 140px; }
}
.okline svg { width: 16px; height: 16px; flex: none; }
.empty svg { width: 40px; height: 40px; }
@media (max-width: 760px) {
  .topbar { position: static; flex-wrap: wrap; padding: 10px 14px; }
  .topbar .proj-name { order: 5; flex: 1 1 100%; min-width: 0; }
  .topbar .spacer { display: none; }
  .tb-btn { padding: 0 9px; font-size: 13px; }
  .tabs { top: 0; padding: 0 10px; }
  main { padding: 14px 14px 50px; }
  .board-head, .row3 { grid-template-columns: 1fr 1fr; }
  .side-r { position: static; }
}

/* ===== นำเข้าแบบ ===== */
.tb-btn.accent-line { border-color: var(--accent); color: #ffd9c4; }
.tb-btn.accent-line:hover { background: #3a2a22; }
.importer {
  position: fixed; z-index: var(--z-importer); left: 50%; top: 50%; height: min(820px, calc(100vh - 40px));
  transform: translate(-50%, -46%) scale(.97); opacity: 0; pointer-events: none;
  background: var(--card); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .5);
  display: flex; flex-direction: column; transition: transform .38s var(--ease), opacity .25s;
}
.importer.on { transform: translate(-50%, -50%); opacity: 1; pointer-events: auto; }
.imp-h { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.imp-h > svg { width: 28px; height: 28px; color: var(--accent); }
.imp-h h3 { margin: 0; font-size: 17px; }
.imp-b { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1.1fr; }
.imp-l { padding: 16px 18px; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; overflow: auto; }
.imp-r { padding: 14px 18px; overflow: auto; background: var(--card); }
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 3px; text-align: center; cursor: pointer; margin-bottom: 12px;
  padding: 20px 14px; border: 1.8px dashed var(--line-2); border-radius: 8px; background: var(--surface);
  transition: border-color .2s, background .2s, transform .2s var(--ease);
}
.drop:hover { border-color: var(--ink-2); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); transform: scale(1.01); }
.drop.got { border-style: solid; border-color: var(--blue); }
.drop-ic svg { width: 30px; height: 30px; color: var(--ink-2); transition: transform .3s var(--ease); }
.drop:hover .drop-ic svg, .drop.over .drop-ic svg { transform: translateY(-4px); color: var(--accent); }
.imp-seg { align-self: flex-start; margin-bottom: 8px; }
.imp-progress { height: 0; overflow: hidden; transition: height .25s; display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--ink-2); }
.imp-progress.on { height: 34px; margin-bottom: 8px; }
.imp-progress .bar { height: 6px; background: var(--paper-2); border-radius: 3px; overflow: hidden; }
.imp-progress .bar i { display: block; height: 100%; background: repeating-linear-gradient(45deg, var(--accent) 0 8px, #e8703a 8px 16px); background-size: 22px 22px; animation: stripes .8s linear infinite; transition: width .4s var(--ease); }
@keyframes stripes { to { background-position: 22px 0; } }
.imp-text-h { display: flex; align-items: center; margin-bottom: 4px; }
#impText { flex: 1; min-height: 220px; resize: vertical; font: 13px/1.6 var(--mono), var(--sans); }
.imp-f { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--paper); border-radius: 0 0 10px 10px; }
.imp-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 9px; border-radius: 99px; color: var(--c); background: color-mix(in srgb, var(--c) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--c) 35%, #fff); white-space: nowrap; }
.chip b { font-family: var(--mono); }
.chip.sm { font-size: 11px; padding: 1px 7px; }
.chip svg { width: 13px; height: 13px; }
.imp-group { margin-bottom: 12px; }
.imp-group > .label { margin: 6px 0; }
.imp-row { display: grid; gap: 8px; align-items: center; padding: 6px 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; margin-bottom: 4px; animation: itemIn .3s var(--ease) both; }
.imp-row .t b { font-weight: 500; font-size: 13px; }
.imp-row .t div { font-size: 11.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.imp-row input { padding: 3px 6px; text-align: right; }
.est { font-size: 10.5px; color: var(--blue); border: 1px dashed #9fb7cd; border-radius: 3px; padding: 0 4px; }
.est.warn { color: var(--bad); border-color: #e0a19b; }
.imp-log { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--ink-2); }
.imp-log li { margin-bottom: 3px; animation: itemIn .3s var(--ease) both; }
.btn[disabled] { opacity: .45; pointer-events: none; }
@media (max-width: 900px) { .imp-b { grid-template-columns: 1fr; overflow: auto; } .imp-l { border-right: 0; } .importer { height: calc(100vh - 20px); } }

/* ===== กล่องยืนยัน ===== */
.modal { position: fixed; inset: 0; z-index: var(--z-modal); display: grid; place-items: center; background: rgba(20, 26, 32, .4); opacity: 0; pointer-events: none; transition: opacity .2s; }
.modal.on { opacity: 1; pointer-events: auto; }
.modal-box { width: min(420px, calc(100vw - 32px)); background: var(--card); border: 1px solid var(--line-2); border-radius: 10px; padding: 20px 22px 16px; box-shadow: 0 30px 60px -20px rgba(0,0,0,.5); transform: translateY(12px) scale(.97); transition: transform .3s var(--ease); }
.modal.on .modal-box { transform: none; }
.modal-box h3 { margin: 0 0 8px; font-size: 17px; }
.modal-box p { margin: 0 0 16px; color: var(--ink-2); line-height: 1.6; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; }
.btn.danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-solid:hover { background: #8f1d17; }

/* ===== Panel Board Schedule (รูปแบบตามแบบตัวอย่าง) ===== */
.pbs { background: var(--surface); color: #111; border: 1.4px solid #111; font-size: 12px; line-height: 1.35; }
.pbs-title { text-align: center; font-weight: 700; padding: 6px 8px; border-bottom: 1.4px solid #111; }
.pbs-head { display: grid; grid-template-columns: 1.2fr .8fr 1fr; border-bottom: 1.4px solid #111; padding: 2px 0; }
.pbs-head > div { padding: 2px 10px; display: flex; gap: 8px; min-width: 0; }
.pbs-head > div b { font-weight: 600; white-space: nowrap; }
.pbs-head > div span { min-width: 0; overflow-wrap: anywhere; }
table.pbt { width: 100%; border-collapse: collapse; }
table.pbt th, table.pbt td { border: 1px solid #111; padding: 2px 6px; text-align: center; white-space: nowrap; }
table.pbt thead th { font-weight: 700; font-size: 11.5px; background: var(--surface); }
table.pbt td.l { text-align: left; white-space: normal; }
table.pbt td.r { text-align: right; }
table.pbt td.muted { color: #6b7680; }
table.pbt tr.space td { color: #6b6b6b; }
table.pbt .c-no { width: 46px; }
table.pbt .c-desc { min-width: 190px; }
table.pbt tbody tr { transition: background .15s; }
table.pbt tbody tr:hover { background: var(--tint-hover); }
.pbs-foot { display: grid; grid-template-columns: 1.15fr 1fr 1fr; border-top: 0; }
.pbs-foot > div { border-right: 1px solid #111; border-bottom: 1px solid #111; padding: 6px 10px; }
.pbs-foot > div:last-child { border-right: 0; }
.pbs-fl { font-weight: 700; margin-bottom: 6px; }
.pbs-feeder-box { border: 1.3px solid #c0392b; padding: 8px 12px; text-align: center; font-family: var(--mono); font-size: 11.5px; line-height: 1.55; }
.pbs-feeder-box .th { margin-top: 6px; font-family: var(--sans); }
.pbs-feeder-sub { margin-top: 6px; font-size: 11px; color: #333; }
table.pbs-sum { width: 100%; border-collapse: collapse; }
table.pbs-sum td { padding: 3px 6px; }
table.pbs-sum td.eq { width: 18px; text-align: center; }
table.pbs-sum td.r { text-align: right; font-family: var(--mono); }
.pbs-total { display: grid; grid-template-columns: 1.15fr 1fr 130px 44px; align-items: stretch; }
.pbs-total > div { padding: 8px 10px; display: flex; align-items: center; }
.pbs-note { font-size: 11px; border-right: 1px solid #111; }
.pbs-tl { justify-content: flex-end; font-weight: 700; }
.pbs-tv { justify-content: flex-end; font-weight: 700; font-size: 15px; border-left: 1px solid #111; border-right: 1px solid #111; }
.pbs-tu { font-weight: 700; }
@media (max-width: 760px) { .pbs-head { grid-template-columns: 1fr; } .pbs-foot { grid-template-columns: 1fr; } .pbs-total { grid-template-columns: 1fr 1fr 1fr; } }

/* ===== ตารางโหลด: ลบวงจร / เฟส / Balance Load ===== */
.unb { display: inline-block; font: 600 11.5px var(--mono); padding: 1px 7px; border-radius: 99px; border: 1px solid transparent; }
.unb.ok { color: var(--ok-ink); background: var(--ok-bg); border-color: var(--ok-line); }
.unb.warn { color: var(--warn-ink); background: var(--warn-bg); border-color: var(--warn-line); }
.unb.bad { color: #7c1d17; background: var(--bad-soft); border-color: #e3aaa5; }
.flash { animation: flashPop .9s var(--ease); }
@keyframes flashPop { 0% { transform: scale(1.18); box-shadow: 0 0 0 0 rgba(210, 74, 15, .5); } 60% { transform: none; box-shadow: 0 0 0 8px rgba(210, 74, 15, 0); } 100% { box-shadow: none; } }
.btn.on { background: var(--ink-fill); color: #fff; border-color: var(--ink); }
.btn.on:hover { background: #2c3843; }
.btn.accent.sm:hover { background: #b93f0b; }
.sched-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 14px; margin-bottom: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); animation: viewIn .35s var(--ease); }
.sched-top > div { flex: 1; min-width: 220px; }
.sheet-tools { flex-wrap: wrap; row-gap: 6px; }
.sheet-tools .spacer { flex: 1; }
.spare-ctl { display: inline-flex; align-items: center; gap: 2px; padding: 0 2px; border: 1px dashed var(--line-2); border-radius: 6px; background: #fff8; }
.spare-ctl b { min-width: 18px; text-align: center; font-weight: 600; }
.spare-ctl .btn.sm { padding: 2px 5px; }
.phase-h { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.phase-h .label { flex: 1; }
.phase-h .btn.sm { padding: 2px 8px; }

.ph-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; vertical-align: middle; background: transparent; }
.ph-dot.phA { background: var(--phA); } .ph-dot.phB { background: var(--phB); } .ph-dot.phC { background: var(--phC); }
table.pbt td.c-act, table.pbt th.c-act { width: 30px; padding: 0 2px; border-color: #d8d2c4; }
table.pbt td.desc-click { cursor: pointer; text-decoration: underline dotted transparent; text-underline-offset: 3px; transition: color .15s, text-decoration-color .15s, background .15s; }
table.pbt td.desc-click:hover { color: var(--blue); text-decoration-color: var(--blue); background: var(--tint-blue); }
.row-x {
  width: 22px; height: 22px; line-height: 20px; padding: 0; border: 1px solid transparent; border-radius: 50%; background: transparent; color: var(--ink-3);
  font: 600 15px/20px var(--mono); cursor: pointer; opacity: .45; transition: opacity .15s, background .15s, color .15s, transform .2s var(--ease), border-color .15s;
}
tr:hover > td > .row-x, .row-x:focus-visible { opacity: 1; }
.row-x:hover { background: var(--bad-soft); color: var(--bad); border-color: #e3aaa5; transform: scale(1.12); }
.row-x:active { transform: scale(.94); }
.mini-sched td.x { width: 24px; text-align: right; }
.mini-sched tr { transition: background .15s; } .mini-sched tr:hover { background: var(--tint-hover); }
@media (hover: none) { .row-x { opacity: 1; } }
@media print { .c-act, .row-x, .sched-top, .spare-ctl, .sheet-tools { display: none !important; } }

/* ===== นำเข้าแบบ: เลือกชั้น/แผงต่อแถว, ย้ายหลายแถว, แผงที่จะสร้าง ===== */
.importer { width: min(1260px, calc(100vw - 32px)); }
.imp-b { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); }
.imp-row {
  grid-template-columns: 20px 104px minmax(0, 1fr) 62px 28px; grid-template-areas: "ck chip t qty x" ". dest dest dest dest";
  row-gap: 5px; transition: border-color .2s, background .2s, box-shadow .2s, transform .2s var(--ease);
}
.imp-row .ck { grid-area: ck; width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.imp-row > .chip { grid-area: chip; }
.imp-row > .t { grid-area: t; }
.imp-row > input[data-imp-qty] { grid-area: qty; }
.imp-row > button { grid-area: x; }
.imp-row .imp-dest { grid-area: dest; display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 6px; }
.imp-row .imp-dest select, .imp-row .imp-dest input { padding: 2px 6px; font-size: 12.5px; text-align: left; height: 26px; }
.imp-row:hover { border-color: var(--line-2); transform: translateX(1px); }
.imp-row.sel { border-color: var(--blue); background: var(--tint-blue); }
.imp-row.moved { box-shadow: inset 3px 0 0 var(--accent); }
.imp-row.moved .imp-dest select { border-color: var(--accent); background: var(--accent-soft); }
@media (max-width: 1100px) { .imp-row { grid-template-columns: 20px minmax(0, 1fr) 62px 28px; grid-template-areas: "ck t qty x" ". dest dest dest"; } .imp-row > .chip { display: none; } }
.imp-group-h { display: flex; align-items: center; gap: 10px; margin: 6px 0; position: sticky; top: -14px; padding: 4px 0; background: color-mix(in srgb, var(--card) 93%, transparent); z-index: 2; backdrop-filter: blur(3px); }
.imp-group-h .check input { width: 15px; height: 15px; accent-color: var(--accent); }
.imp-bulk {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; position: sticky; top: -14px; z-index: 3; margin-bottom: 10px; padding: 8px 10px;
  background: var(--ink-fill); color: #efe9dc; border-radius: 8px; box-shadow: 0 10px 24px -14px rgba(0, 0, 0, .6); animation: bulkIn .3s var(--ease);
}
@keyframes bulkIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.imp-bulk select, .imp-bulk input { width: auto; min-width: 110px; padding: 3px 8px; font-size: 12.5px; background: var(--surface); color: var(--ink); }
.imp-bulk .btn.dark { background: var(--accent-fill); border-color: var(--accent-fill); }
.imp-bulk .btn.ghost { color: #c9d1d8; }
.imp-bulk .btn.ghost:hover { color: #fff; background: #ffffff1a; }
.imp-bal svg { width: 16px; height: 16px; color: var(--accent); }
.imp-panel { padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; margin-bottom: 5px; animation: itemIn .3s var(--ease) both; }
.imp-panel-h { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.pmini { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 10px; margin-top: 5px; }
.pmini i { display: block; height: 4px; border-radius: 2px; transition: width .6s var(--ease); grid-column: 1; }
.pmini .unb { grid-column: 2; grid-row: 1 / span 3; align-self: center; white-space: nowrap; }
.imp-log li.w { color: var(--bad); }

/* ลากไฟล์มาวางที่ไหนในหน้าก็ได้ */
body.dragging::after {
  content: 'วางไฟล์เพื่อนำเข้า (รูป · PDF · .txt · .csv · โครงการ .json)'; position: fixed; inset: 10px; z-index: var(--z-drop); display: grid; place-items: center; text-align: center;
  font: 600 20px var(--sans); color: var(--accent); background: rgba(251, 249, 244, .86); border: 3px dashed var(--accent); border-radius: 14px; pointer-events: none;
  animation: dropPulse 1.2s var(--ease) infinite alternate; backdrop-filter: blur(2px);
}
@keyframes dropPulse { from { border-color: var(--accent); } to { border-color: #e8703a; transform: scale(.995); } }
@media (max-width: 900px) { .imp-b { grid-template-columns: 1fr; } .importer { width: calc(100vw - 16px); } }

/* ===== ขัดเกลา: แถบบน / โฟกัส / transition ===== */
@media (max-width: 1080px) {
  .tb-btn:not(.primary) .lbl { display: none; }
  .tb-btn { padding: 0 9px; }
  .topbar { gap: 10px; flex-wrap: wrap; }
  .topbar .proj-name { min-width: 120px; flex: 1 1 140px; }
}
@media (max-width: 560px) { .tb-btn.primary .lbl { display: none; } }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.tb-btn:focus-visible { outline-color: #9cc3e6; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }   /* ช่องติ๊กไม่มีกรอบให้เงา 15% เกาะ → ต้องมี outline ให้เห็นตำแหน่งโฟกัส */
.scrim { backdrop-filter: blur(2px); }
.topbar { overflow: visible; }
.topbar::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -3px; height: 3px; pointer-events: none; opacity: 0; transition: opacity .25s;
  background: linear-gradient(90deg, transparent, #ffd2b4, transparent) no-repeat; background-size: 35% 100%;
}
body.calculating .topbar::after { opacity: 1; animation: sweep 1s linear infinite; }
@keyframes sweep { from { background-position: -35% 0; } to { background-position: 135% 0; } }
.view .card, .view .sheet, .view .bigstat, .view .sched-top { animation: cardIn .5s var(--ease) both; }
.view .card:nth-child(2), .view .sheet:nth-child(2) { animation-delay: .05s; }
.view .card:nth-child(3), .view .sheet:nth-child(3) { animation-delay: .1s; }
.view .card:nth-child(n+4), .view .sheet:nth-child(n+4) { animation-delay: .14s; }
@keyframes cardIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.calm .card, .calm .sheet, .calm .bigstat, .calm .sched-top { animation: none !important; }
table.pbt tr.rephased > td { animation: rephase 1.1s var(--ease); }
@keyframes rephase { 0% { background: var(--accent-soft); } 100% { background: transparent; } }
table.pbt tbody tr { will-change: transform; }
.tile, .item, .node, .btn, .tb-btn, .tab { -webkit-tap-highlight-color: transparent; }
.card, .sheet { transition: box-shadow .25s var(--ease), border-color .25s; }
.card:hover { border-color: var(--line-2); }

/* ===== ภาพรวม (Dashboard) ===== */
.dash { display: flex; flex-direction: column; gap: 26px; }
.dash-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); position: sticky; top: 98px; z-index: 12; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { cursor: pointer; border: 1px solid var(--line-2); background: var(--surface); border-radius: 99px; padding: 2px 11px; font-size: 12.5px; color: var(--ink-2); transition: background .15s, color .15s, border-color .15s; }
.chip:hover { border-color: var(--ink-2); color: var(--ink); }
.chip.on { background: var(--ink-fill); border-color: var(--ink); color: #fff; }
.dash-sec { scroll-margin-top: 110px; }
.sec-h { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px dashed var(--line-2); }
.sec-h h2 { margin: 0; font-size: 18px; font-weight: 600; }
.sec-no { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 4px; background: var(--ink-fill); color: #fff; font: 600 12px var(--mono); }
.sec-h .spacer { flex: 1; }
.check.dim { opacity: .55; }
.check.dim input { cursor: not-allowed; }
.tag.coord { border-color: var(--blue); color: var(--blue); background: var(--blue-soft); font-weight: 600; margin-left: 5px; white-space: nowrap; } /* ที่มาของขนาด CB: ประสานสายป้อนหลายชั้น */
.tag.live { border-color: var(--ok); color: var(--ok); background: var(--tint-ok); margin-left: 6px; }
.ok-t { color: var(--ok); } .warn-t { color: var(--warn-t); font-weight: 600; } .bad-t { color: var(--bad); font-weight: 600; } .forced-t { color: var(--accent); font-weight: 600; }

.plans { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.plan { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 9px; position: relative; box-shadow: var(--shadow); transition: transform .2s var(--ease), border-color .2s; }
.plan:hover { transform: translateY(-2px); border-color: var(--line-2); }
.plan.on { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink), var(--shadow); }
.plan.on::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent); border-radius: var(--radius) 0 0 var(--radius); }
.plan.bad { border-color: #e3aaa5; background: var(--bad-soft); }
.plan-h { display: flex; align-items: center; gap: 4px; }
.plan-h b { font-size: 15.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.plan-sub { font-size: 12px; color: var(--ink-2); margin-top: -4px; }
.plan-kv { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 8px 0; border-top: 1px dotted var(--line-2); border-bottom: 1px dotted var(--line-2); }
.plan-kv .v { font: 600 22px var(--mono); letter-spacing: -1px; }
.plan-kv .v small { font: 400 12px var(--mono); color: var(--ink-3); margin-left: 3px; letter-spacing: 0; }
.plan-trafo { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; }
.ok-t.num, .ok-t { color: var(--ok); }
.gauge { height: 8px; border-radius: 99px; background: repeating-linear-gradient(90deg, #0000000d 0 1px, transparent 1px 10%), var(--paper-2); overflow: hidden; }
.gauge i { display: block; height: 100%; border-radius: 99px; background: var(--ok); transition: width .6s var(--ease); }
.gauge.warn i { background: #d99a0b; } .gauge.bad i { background: var(--bad); }
.num.ok-t { color: var(--ok); } .num.warn-t { color: var(--warn-t); } .num.bad-t { color: var(--bad); }
.plan-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--ink-2); }
.plan-act { display: flex; gap: 6px; align-items: center; margin-top: auto; padding-top: 4px; }
.plan-act .spacer { flex: 1; }

.dash-group + .dash-group { margin-top: 18px; }
.dash-gh { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.pcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 12px; }
.pcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 7px; border-top: 3px solid var(--blue); }
.pcard.sel { box-shadow: 0 0 0 1px var(--blue); }
.pc-h { display: flex; align-items: center; gap: 6px; } .pc-h .spacer { flex: 1; }
.pc-h b { font-size: 15px; }
.pc-sub { font-size: 12px; color: var(--ink-2); margin-top: -3px; }
.pc-kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pc-kv > div { display: flex; flex-direction: column; }
.pc-kv b { font: 600 17px var(--mono); letter-spacing: -.5px; }
.pc-kv small { font-size: 11px; color: var(--ink-3); }
.share { height: 5px; background: var(--paper-2); border-radius: 99px; overflow: hidden; } .share i { display: block; height: 100%; background: var(--blue); }
.ph3 { display: flex; height: 9px; border-radius: 3px; overflow: hidden; gap: 2px; }
.ph3 i { display: block; } .ph3 .a { background: var(--phA); } .ph3 .b { background: var(--phB); } .ph3 .c { background: var(--phC); }
.pc-spec { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 2px 0 0; font-size: 12.5px; }
.pc-spec dt { color: var(--ink-3); } .pc-spec dd { margin: 0; font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.pc-act { display: flex; gap: 6px; margin-top: auto; padding-top: 4px; }

.sbars { display: flex; flex-direction: column; gap: 6px; }
.sbar { display: grid; grid-template-columns: 76px 1fr 54px; gap: 8px; align-items: center; font-size: 12.5px; }
.sbar .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sbar .track { height: 10px; background: var(--paper-2); border-radius: 2px; overflow: hidden; } .sbar .track i { display: block; height: 100%; background: var(--blue); }
.sbar .num { text-align: right; font-size: 12px; }
.util-line { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; margin-top: 14px; padding-top: 12px; border-top: 1px dotted var(--line-2); font-size: 12.5px; }

.log-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; } .log-bar .spacer { flex: 1; }
.log-wrap { max-height: 360px; overflow: auto; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); }
.log-tbl { width: 100%; font-size: 12.5px; } .log-tbl th { position: sticky; top: 0; background: var(--paper-2); z-index: 1; }
.log-tbl td.pn { max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.nowrap { white-space: nowrap; }
.lg { display: inline-block; font: 500 11px var(--mono); padding: 1px 7px; border-radius: 3px; border: 1px solid currentColor; }
.lg-plan { color: var(--blue); } .lg-item { color: var(--ink); } .lg-panel { color: var(--tag-sdb); } .lg-circuit { color: var(--lg-purple); }
.lg-breaker { color: var(--accent); } .lg-balance { color: var(--ok); } .lg-setting { color: var(--ink-3); } .lg-file { color: var(--lg-cyan); } .lg-import { color: var(--lg-amber); }
.chip.lg-plan.on { background: var(--blue); } .chip.lg-item.on { background: var(--ink-fill); } .chip.lg-panel.on { background: #a63a0b; } .chip.lg-circuit.on { background: #6d28d9; }
.chip.lg-breaker.on { background: var(--accent); } .chip.lg-balance.on { background: var(--ok); } .chip.lg-setting.on { background: var(--ink-3); } .chip.lg-file.on { background: #0e7490; } .chip.lg-import.on { background: #a06b00; }
.chip[class*="lg-"]:not(.on) { color: var(--ink-2); }

/* ===== เบรกเกอร์ย่อย: dropdown + ลากวาง ===== */
.cb-tray { position: sticky; top: 98px; z-index: 12; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; margin-bottom: 14px; background: var(--card); border: 1px solid var(--line-2); border-left: 4px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow); }
.cb-chip { cursor: grab; user-select: none; touch-action: none; display: inline-flex; align-items: baseline; gap: 1px; padding: 3px 9px; font: 600 13px var(--mono); background: var(--surface); border: 1px solid var(--ink-2); border-bottom-width: 3px; border-radius: 4px; transition: transform .12s var(--ease), background .12s; }
.cb-chip small { font-weight: 400; font-size: 10px; color: var(--ink-3); }
.cb-chip:hover { background: var(--accent-soft); border-color: var(--accent); transform: translateY(-1px); }
.cb-chip:active { cursor: grabbing; }
.cb-grip { cursor: ns-resize; user-select: none; touch-action: none; letter-spacing: -2px; color: var(--ink-3); padding: 2px 3px; margin-right: 1px; font-size: 13px; line-height: 1; border-radius: 3px; }
.cb-grip:hover { background: var(--accent-soft); color: var(--accent); }
.at-cell { white-space: nowrap; }
.cb-sel { border: 1px solid transparent; background: transparent; border-radius: 3px; padding: 1px 2px; font: 12px var(--mono); cursor: pointer; }
.cb-sel:hover, .cb-sel:focus { border-color: var(--line-2); background: var(--surface); outline: none; }
.at-cell.forced { background: var(--tint-warm); box-shadow: inset 0 0 0 1.5px var(--accent); }
.at-cell.forced .cb-sel { color: var(--accent); font-weight: 600; }
.cb-reset { cursor: pointer; border: 0; background: none; color: var(--accent); font-size: 13px; padding: 0 2px; }
.cb-reset:hover { transform: rotate(-90deg); transition: transform .2s; }
tr.cb-over, tr.cb-over td { background: var(--tint-warm) !important; }
tr.cb-over { outline: 2px solid var(--accent); outline-offset: -2px; }
.cb-ghost { position: fixed; left: 0; top: 0; z-index: var(--z-ghost); pointer-events: none; padding: 3px 10px; font: 600 13px var(--mono); background: var(--ink-fill); color: #fff; border-radius: 4px; box-shadow: 0 6px 16px -6px rgba(0, 0, 0, .5); white-space: nowrap; }
.cb-ghost.ok { background: var(--accent); }
body.cb-dragging, body.cb-dragging * { cursor: grabbing !important; user-select: none !important; }
.mini-sched td.at-cell { padding: 1px 2px; }
@media (max-width: 760px) { .dash-nav, .cb-tray { top: 0; position: static; } .plans, .pcards { grid-template-columns: 1fr; } }
@media print { .cb-tray, .dash-nav, .cb-grip, .cb-reset { display: none !important; } .cb-sel { border: 0; background: none; appearance: none; -webkit-appearance: none; } .at-cell.forced { background: none; box-shadow: none; } }

/* ลากแผงในผังแผงไฟ */
.tree .node[data-select] { cursor: grab; user-select: none; }
.tree .node.dragging { opacity: .45; }
.tree .node.drop-ok { background: var(--tint-ok) !important; outline: 2px solid var(--ok); outline-offset: -2px; }
.tree .node.drop-bad { background: var(--bad-soft) !important; outline: 2px dashed var(--bad); outline-offset: -2px; cursor: not-allowed; }

/* ---------- ย้ายเฟสวงจร (ลาก / dropdown / ← →) ---------- */
.ph-grip { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; margin-right: 3px; border-radius: 50%; font: 600 9px/1 var(--mono); color: #fff; cursor: grab; user-select: none; touch-action: none; vertical-align: middle; }
.ph-grip.phA { background: var(--phA); } .ph-grip.phB { background: var(--phB); } .ph-grip.phC { background: var(--phC); }
.ph-grip:hover, .ph-grip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cb-grip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ph-sel { border: 1px solid transparent; background: transparent; border-radius: 3px; padding: 0 1px; font: 10.5px var(--mono); color: var(--ink-3); cursor: pointer; margin-right: 3px; max-width: 30px; }
.ph-sel:hover, .ph-sel:focus { border-color: var(--line-2); background: var(--surface); outline: none; }
tr.ph-pinned td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
tr.ph-pinned .ph-sel { color: var(--accent); font-weight: 600; }
.ph-buckets { display: inline-flex; gap: 4px; align-items: center; }
.ph-b { position: relative; display: inline-flex; align-items: center; gap: 4px; min-width: 64px; padding: 2px 6px; border: 1px solid var(--line-2); border-radius: 4px; background: var(--paper); font-size: 11px; overflow: hidden; }
.ph-b b { font: 600 10px var(--mono); position: relative; z-index: 1; }
.ph-b small { position: relative; z-index: 1; color: var(--ink-3); margin-left: auto; }
.ph-b i { position: absolute; left: 0; bottom: 0; height: 3px; }
.ph-b.phA i { background: var(--phA); } .ph-b.phB i { background: var(--phB); } .ph-b.phC i { background: var(--phC); }
.ph-b.cb-over { outline: 2px solid var(--accent); background: var(--tint-warm); }
body.cb-dragging .ph-b { border-style: dashed; border-color: var(--accent); }
@media print { .ph-grip, .ph-sel, .ph-buckets { display: none !important; } tr.ph-pinned td:first-child { box-shadow: none; } }

/* ---------- คำเตือนรวม / เปรียบเทียบแปลน / ประวัติเวอร์ชัน ---------- */
.wtag { display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 11px; background: var(--paper-2, #f3efe6); color: var(--ink-2); white-space: nowrap; }
.wtag.wc-vd, .chip.wc-vd.on { background: #fde8d8; color: #9a3412; }
.wtag.wc-phase, .chip.wc-phase.on { background: #e9e3f7; color: #5b21b6; }
.wtag.wc-cb, .chip.wc-cb.on { background: #e3eef8; color: #1f5d94; }
.wtag.wc-cap, .chip.wc-cap.on { background: #fdf0d5; color: #8a5a00; }
.wtag.wc-data, .chip.wc-data.on { background: #ececec; color: #44403c; }
.wtag.wc-selectivity, .chip.wc-selectivity.on { background: #dcefe9; color: #0f5e4a; }
.warn-tbl td { vertical-align: top; } .warn-tbl td.r, .cmp-tbl .r { text-align: right; }
.wplans { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.wplan { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 8px 10px; border: 1px solid var(--line); border-left: 3px solid var(--ok); border-radius: 6px; background: var(--surface); }
.wplan.warn { border-left-color: #d9a400; } .wplan.bad { border-left-color: var(--bad); }
.wplan b { flex: 1 1 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wplan .btn { margin-left: auto; }
.cmp-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; }
.cmp-bar select { max-width: 260px; }
.cmp-grid { align-items: start; }
.cmp-tbl small { color: var(--ink-3); }
.hist-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.hist-bar input { flex: 1 1 220px; min-width: 0; }
.hist-list { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow: auto; }
.hist-list li { display: flex; align-items: center; gap: 8px; padding: 4px 2px; border-bottom: 1px dotted var(--line); font-size: 12.5px; }
.hist-list li.on { background: var(--tint-warm); }
.hist-list .hn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); max-width: 40%; }
.hdiff { border: 1px solid var(--line-2); border-radius: 6px; padding: 10px; margin: 8px 0; background: var(--card); }
.hdiff-h { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.dkpi { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; margin-bottom: 6px; }
.dsec { margin-top: 6px; }
.dlist { list-style: none; margin: 2px 0 0; padding: 0; font-size: 12.5px; }
.dlist li { padding: 2px 0; } .dlist .add { color: var(--ok); } .dlist .del { color: var(--bad); } .dlist .chg { color: var(--ink); }
.dfield { display: inline-block; margin-right: 8px; font-size: 12px; color: var(--ink-2); } .dfield s { color: var(--ink-3); }
@media (max-width: 640px) { .hist-list .hn { display: none; } .cmp-bar select { max-width: 100%; flex: 1 1 140px; } }
@media print { .hist-card, #dash-cmp, .hist-bar { display: none !important; } }
table.pbt td.ph-cell { min-width: 74px; text-align: left; padding-left: 3px; }
table.pbt td.ph-cell .no { display: inline-block; min-width: 16px; text-align: right; }
.warn-tbl td:nth-child(3) { min-width: 180px; }

/* ---------- เบรกเกอร์ตามยี่ห้อ (brandui.js) ---------- */
.wtag.wc-brand, .chip.wc-brand.on { background: #f6e3cf; color: #8a3b0a; }
[data-brcb] { cursor: pointer; }
[data-brcb]:hover, [data-brcb]:focus-visible { outline: 1px dashed var(--accent); outline-offset: -2px; background: var(--accent-soft); }
.br-mdl { font: 500 10px var(--mono); color: var(--blue); white-space: nowrap; line-height: 1.2; }
#brTip, #brPop { position: fixed; z-index: var(--z-pop); background: var(--card); color: var(--ink); border: 1px solid var(--line-2); border-radius: var(--radius); box-shadow: 0 10px 30px -12px rgba(29, 38, 47, .45); font-size: 12.5px; }
#brTip { max-width: 360px; padding: 8px 10px; pointer-events: none; line-height: 1.5; }
.br-ver { color: var(--ok); font-weight: 600; font-size: 12px; margin-top: 3px; }
.br-ver-l a { color: var(--blue); }
#brTip .br-src { display: inline-block; margin-top: 3px; font-size: 11px; padding: 0 6px; border-radius: 3px; background: var(--accent-soft); color: var(--accent); }
#brTip .br-hint { margin-top: 4px; font-size: 11px; color: var(--ink-3); }
#brPop { width: min(440px, calc(100vw - 16px)); padding: 10px 12px; }
#brPop .br-pop-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 2px; }
#brPop .row2 { margin-top: 8px; }
#brPop .field { margin-bottom: 6px; }
.br-list { display: flex; flex-direction: column; gap: 4px; max-height: 260px; overflow: auto; margin: 4px 0 8px; }
.br-opt { display: grid; grid-template-columns: minmax(90px, auto) 1fr; gap: 1px 10px; text-align: left; padding: 5px 8px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--ink); cursor: pointer; font: inherit; }
.br-opt .nm { font-weight: 600; font-family: var(--mono); }
.br-opt .tiny { grid-column: 1 / -1; color: var(--ink-2); }
.br-opt:hover:not([disabled]) { border-color: var(--blue); background: var(--blue-soft); }
.br-opt.on { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.br-opt[disabled] { cursor: not-allowed; opacity: .55; background: var(--paper-2); }
.br-opt[disabled] .tiny { color: var(--bad); }
.br-pop-f { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.br-card .br-ov { margin: 4px 0 10px; font-size: 13px; }
.br-card details ul { margin: 4px 0 0 16px; padding: 0; }
tr.br-grp td { background: var(--paper-2); font-size: 12px; }
@media print { #brTip, #brPop { display: none !important; } [data-brcb] { outline: none !important; background: none !important; } }


/* ===== แถบเตือน Ik" > IC (ความปลอดภัยต่อชีวิต) — แสดงทุกแท็บทันทีที่พบ ===== */
.ik-banner { background: #b3261e; color: #fff; padding: 9px 20px 10px; border-bottom: 3px solid #7d1912; font-size: 14px; font-weight: 600; position: relative; z-index: var(--z-tabs); }
.ik-banner ul { margin: 3px 0 0; padding-left: 20px; font-weight: 400; font-size: 13px; }
.sel-notice { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 8px 20px; background: var(--blue-soft); color: var(--ink); border-bottom: 1px solid var(--line-2); border-left: 4px solid var(--blue); font-size: 13px; position: relative; z-index: var(--z-tabs); }
.sel-notice[hidden] { display: none; }
.sel-notice span { flex: 1 1 320px; }
.ik-banner .more { font-weight: 400; font-size: 12.5px; opacity: .9; }
.ik-banner .advice { margin-top: 6px; padding: 5px 9px; font-weight: 400; font-size: 12.5px; background: rgba(0, 0, 0, .22); border-radius: 3px; }
table.ps td.ic-bad, table.pbt td.ic-bad { background: var(--bad-soft); color: var(--bad); font-weight: 700; outline: 2px solid var(--bad); outline-offset: -2px; }

/* ===== ค้นหาแผงด่วน (Ctrl+K / "/") + ปุ่ม Undo/Redo/ธีม ===== */
.tree-search { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px dashed var(--line); }
.tree-search input { flex: 1; min-width: 0; padding: 5px 9px; }
.kbd { font: 500 10.5px var(--mono); border: 1px solid var(--line-2); border-radius: 3px; padding: 0 5px; color: var(--ink-2); white-space: nowrap; }
.tree .node.dim { opacity: .42; }
.tree .node.hit { box-shadow: inset 3px 0 0 var(--blue); }
.tree-empty { padding: 14px 12px; color: var(--ink-2); font-size: 13px; }
.logo-box { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.logo-prev { width: 96px; height: 56px; border: 1px dashed var(--line-2); border-radius: 4px; display: grid; place-items: center; background: var(--surface); overflow: hidden; }
.logo-prev img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ===== ธีมมืด (งาน CAD) — จำค่าใน localStorage ('ls-theme') ===== */
html[data-theme="dark"] {
  color-scheme: dark;
  --paper: #12161a; --paper-2: #181e24; --card: #1b2229; --surface: #222b33;
  --ink: #e8e3d6; --ink-2: #aeb8c1; --ink-3: #98a3ad; --ink-fill: #2e3a46;
  --line: #2f3a44; --line-2: #44515d;
  --accent: #ee6a2c; --accent-soft: #3b2519;
  --blue: #74b3ec; --blue-soft: #17304a; --formula: #a9cdee;
  --ok: #5fbf71; --bad: #ff7a6e; --bad-soft: #3f1d1a;
  --phA: #d19a62; --phB: #d9dde2; --phC: #9aa2aa; --phN: #7ea6f2;
  --shadow: 0 1px 0 rgba(0, 0, 0, .4), 0 8px 22px -10px rgba(0, 0, 0, .7);
  --tint-th: #222b33; --tint-head: #27313a; --tint-hover: #2a343d; --tint-blue: #17304a; --tint-ok: #1c3a24; --tint-warm: #3a2a1c;
  --warn-ink: #f0c869; --warn-bg: #3b3015; --warn-line: #5c4a1c; --ok-ink: #8fd49c; --ok-bg: #1c3a24; --ok-line: #2f5e3a;
}
html[data-theme="dark"] body { background-image: linear-gradient(rgba(116, 179, 236, .05) 1px, transparent 1px), linear-gradient(90deg, rgba(116, 179, 236, .05) 1px, transparent 1px); }
html[data-theme="dark"] .topbar { background: #0c0f12; }
html[data-theme="dark"] .tag, html[data-theme="dark"] .helper, html[data-theme="dark"] .spare-ctl, html[data-theme="dark"] .empty { background: rgba(255, 255, 255, .04); }
html[data-theme="dark"] table.dt tbody tr:hover, html[data-theme="dark"] .mini-sched tr:hover { background: rgba(255, 255, 255, .06); }
html[data-theme="dark"] .tree .node.drop-ok { background: #1c3a24 !important; }
html[data-theme="dark"] tr.cb-over, html[data-theme="dark"] tr.cb-over td { background: #3a2a1c !important; }
/* กระดาษ: ตารางโหลด/ผังเส้นเดียว/รายงาน คงโทนสว่างเหมือนที่พิมพ์ออกกระดาษจริง (คืนค่า token สว่างเฉพาะในกรอบเหล่านี้) */
html[data-theme="dark"] .sheet, html[data-theme="dark"] .sld-wrap, html[data-theme="dark"] .pbs, html[data-theme="dark"] #report {
  color-scheme: light;
  --paper: #f2eee4; --paper-2: #e9e3d5; --card: #fbf9f4; --surface: #fff;
  --ink: #1d262f; --ink-2: #4f5b66; --ink-3: #5f6b76; --ink-fill: #1d262f;
  --line: #d6cdbb; --line-2: #c3b8a2;
  --accent: #d24a0f; --accent-soft: #f6dccd; --blue: #1f5d94; --blue-soft: #dbe6ef; --formula: #173f63;
  --ok: #2f7d3b; --bad: #b3261e; --bad-soft: #f4d9d6;
  --phA: #8a5528; --phB: #26292d; --phC: #6f757c; --phN: #2e66c7;
  --tint-th: #f6f2ea; --tint-head: #efeae0; --tint-hover: #fffaf0; --tint-blue: #f3f8fc; --tint-ok: #e5f2e6; --tint-warm: #fff1e6;
  --warn-ink: #7a5200; --warn-bg: #fbecc4; --warn-line: #ecd28d; --ok-ink: #1f6130; --ok-bg: #dcefdd; --ok-line: #b4d8b8;
  color: #1d262f;
}
html[data-theme="dark"] .wtag.wc-vd, html[data-theme="dark"] .chip.wc-vd.on { background: #3a2418; color: #f3b48a; }
html[data-theme="dark"] .wtag.wc-phase, html[data-theme="dark"] .chip.wc-phase.on { background: #2a2342; color: #c9b6f4; }
html[data-theme="dark"] .wtag.wc-cb, html[data-theme="dark"] .chip.wc-cb.on { background: #17304a; color: #9fcbf2; }
html[data-theme="dark"] .wtag.wc-cap, html[data-theme="dark"] .chip.wc-cap.on { background: #3b3015; color: #f0c869; }
html[data-theme="dark"] .wtag.wc-data, html[data-theme="dark"] .chip.wc-data.on { background: #2b3138; color: #c8cdd2; }
html[data-theme="dark"] .wtag.wc-selectivity, html[data-theme="dark"] .chip.wc-selectivity.on { background: #16342d; color: #8fd9c0; }
html[data-theme="dark"] .wtag.wc-brand, html[data-theme="dark"] .chip.wc-brand.on { background: #3a2a1c; color: #f0b98a; }
html[data-theme="dark"] .preview { color: #cfe3f6; border-color: #2c4f73; }
html[data-theme="dark"] .preview .num { color: #fff; }

/* ===== แถบบน: กลุ่มปุ่ม (segmented) สูงเท่ากันทั้งแถว — ประวัติ [ย้อน|ซ้ำ] · ไฟล์ [เปิด|บันทึก] · ส่งออก [CSV|Excel|DXF] ===== */
.tb-group { display: inline-flex; align-items: stretch; flex: none; border: 1px solid #45515c; border-radius: 5px; overflow: hidden; }
.tb-group > .tb-btn { border: 0; border-radius: 0; }
.tb-group > .tb-btn + .tb-btn { border-left: 1px solid #39444f; }
.tb-group:hover { border-color: #6c7884; }
.tb-btn .cnt { font: 600 10.5px/1 var(--mono); color: #f0b429; min-width: 1.4ch; text-align: left; }
.tb-btn .cnt:empty { display: none; }
.tb-btn[disabled] { opacity: .42; cursor: not-allowed; }
.tb-btn[disabled]:hover { background: transparent; border-color: #45515c; }
.tb-group > .tb-btn[disabled]:hover { border-color: transparent; }
.tb-btn[disabled]:active { transform: none; }
.tb-btn.icon { width: 36px; padding: 0; justify-content: center; font-size: 16px; flex: none; }
.tb-btn.accent-line, .tb-btn.primary { flex: none; }
@media (max-width: 1360px) { .topbar { gap: 10px; } .tb-group [data-action="open-file"] .lbl, .tb-group [data-action="save-file"] .lbl { display: none; } }
@media (max-width: 1220px) { .brand b { display: none; } .topbar .proj-name { min-width: 120px; } }

/* ===== แถบบนไม่ล้นจอ: ช่องชื่อโครงการหดได้ก่อน (เดิมกว้างคงที่ 220px ทำให้ปุ่มขวาสุดหลุดขอบที่ ~1500px) ===== */
@media (min-width: 761px) {
  .topbar { gap: 12px; }
  .topbar .proj-name { flex: 1 1 200px; min-width: 110px; max-width: 340px; text-overflow: ellipsis; }
  .topbar .calc-chip { flex: none; }
}
@media (max-width: 1480px) { .brand small { display: none; } }

/* ===== a11y / contrast / responsive polish (จาก UX audit) ===== */
:root { --bad-ink: #6e1a14; --accent-fill: #c8430c; --tag-sdb: #a63a0b; --warn-t: #a35f00; --lg-purple: #6d28d9; --lg-cyan: #0e7490; --lg-amber: #8a5c00; }
html[data-theme="dark"] { --bad-ink: #ffb4ab; --tag-sdb: #f3a47a; --warn-t: #f0c869; --lg-purple: #c9b6f4; --lg-cyan: #7fd3e6; --lg-amber: #f0c869; --line-2: #5a6874; }
.tb-btn.primary:hover, .btn.accent:hover, .btn.accent.sm:hover { background: #a93a09; }
.rcd, .steps .ref { color: #b83f0a; border-color: currentColor; }
html[data-theme="dark"] .rcd, html[data-theme="dark"] .steps .ref { color: var(--accent); }
.tag.live { color: var(--ok-ink); }
.tabs { overflow-y: hidden; scrollbar-width: thin; }
.topbar .proj-name:focus-visible, .proj-name:focus-visible { outline: 2px solid #9cc3e6; outline-offset: 2px; }
/* ปิดของ drawer/importer ที่ไม่ได้ใช้ไม่ให้ Tab/โปรแกรมอ่านจอเข้าถึง (inert ตั้งใน JS ด้วย) */
.drawer:not(.on), .importer:not(.on) { visibility: hidden; transition: transform .38s var(--ease), opacity .25s, visibility 0s linear .4s; }
.calc-chip[role="status"] { cursor: default; }
@media (max-width: 900px) { .imp-f { flex-wrap: wrap; } .imp-f .btn { flex: 1 1 auto; } }
@media (pointer: coarse) {
  .btn, .tb-btn, .chip, .tab, .node, input:not([type="checkbox"]):not([type="radio"]), select { min-height: 44px; }
  .row-x { width: 44px; height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
  .calc-chip.busy i { animation: none !important; }
}

/* พรีวิว SLD แบบ CAD (sld-view.js) */
.sldv-wrap { background: #d9dde1; }
.sldv { display: flex; flex-direction: column; height: calc(100vh - 250px); min-height: 420px; }
.sldv-bar { display: flex; align-items: center; gap: 6px; padding: 6px 8px; background: var(--card, #fbf9f4); border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.sldv-svg { flex: 1; width: 100%; cursor: crosshair; touch-action: none; user-select: none; }
