/* หน้าต่างตีบวก (โต๊ะช่าง) — ดู refine-window.js
   แยกไฟล์เพราะหน้านี้เป็นผังสี่คอลัมน์ของตัวเอง ไม่ได้ใช้กฎร่วมกับหน้าต่างอื่นเลย
   ⚠️ โทนอุ่นกว่าหน้าต่างอื่นเล็กน้อยตั้งใจ — มันคือโรงตีเหล็ก */

/* ⚠️ .win ตั้ง max-height: calc(100vh - 150px) และสกินไม้ตั้ง max-height ให้ .body อีกชั้น
   ค่าพวกนั้นคิดมาเพื่อบานเล็ก ๆ หน้านี้จึงถูกบีบเหลือ ~430px แล้วเนื้อหาหายไปครึ่ง
   ต้องปลดทั้งสองชั้น แล้วคุมความสูงจากคอลัมน์แทน */
#windows .win[data-win="refine"] { width: min(92vw, 1020px); max-height: min(90vh, 760px); }
html[data-skin="wood"] body .win[data-win="refine"] > .body { max-height: none; }
/* บนจอคอมทุกคอลัมน์พอดีจอ ไม่ต้องเลื่อนทั้งก้อน · บนมือถือหน้าต่างเตี้ยกว่าเนื้อหา
   จึงต้องเลื่อนได้ ไม่งั้นปุ่มล่างทับคอลัมน์ (เจอจริงตอนถ่ายจอแนวนอน 915x412) */
#windows .win[data-win="refine"] > .body { max-height: none; overflow: auto; padding: 0; }

.rw { display: grid; gap: 10px; padding: 2px; }

/* ── หัว: ตรา + ชื่อ + Ferra ─────────────────────────────────────────────
   ⚠️ Ferra ต้องใหญ่พอให้เป็น "ช่างที่เราไปคุยด้วย" ไม่ใช่รูปโปรไฟล์ในแชท
      ก่อนหน้านี้ย่อเหลือ 72px แล้วรูปที่สั่งทำมาเสียของไปเปล่า ๆ */
.rw-head {
  display: grid; grid-template-columns: 54px auto minmax(0, 1fr) 148px;
  align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: 12px;
  background: linear-gradient(100deg, #f7edd6, #fdf6e6 42%, #f6e3c4);
  border: 1px solid #e0cda0; box-shadow: inset 0 0 26px #e8a04022;
}
.rw-crest { width: 54px; height: 54px; object-fit: contain; }
.rw-title b { display: block; font: 700 20px/1.15 var(--font-head); color: #6b4510; }
.rw-title span { font-size: 12px; color: #9a8258; letter-spacing: .06em; }
.rw-say {
  justify-self: end; align-self: center; position: relative;
  max-width: 320px; padding: 9px 13px; border-radius: 12px;
  background: #fffdf6; border: 1px solid #e0d2ab;
  font-size: 13px; line-height: 1.45; color: #5b4524;
}
.rw-say::after {                      /* หางบอลลูนชี้ไปทาง Ferra */
  content: ''; position: absolute; right: -7px; top: 50%; translate: 0 -50%;
  border: 7px solid transparent; border-left-color: #fffdf6;
}
.rw-ferra { width: 148px; height: 148px; object-fit: contain; object-position: bottom; display: block; margin-bottom: -10px; }

/* ── สี่คอลัมน์ ──────────────────────────────────────────────────────────
   อ่านจากซ้ายไปขวา: เลือกของ → เห็นว่าได้อะไรเพิ่ม → ใช้อะไร → เสี่ยงแค่ไหน */
/* ⚠️ เปอร์เซ็นต์รวมกัน 100% แล้วบวก gap อีก 27px = ล้นขวา 27px เกิดแถบเลื่อนแนวนอน
   ใช้ fr แทน เพราะ fr คิดจาก "ที่ว่างหลังหัก gap แล้ว" */
.rw-cols { display: grid; grid-template-columns: 23fr 28fr 22fr 27fr; gap: 9px; align-items: start; }
/* ⚠️ ใช้ max-height ไม่ใช่ height — ตั้ง height ตายตัวแล้วคอลัมน์ที่เนื้อหาสั้น
   (เช่นรายการของ 2 ชิ้น) จะเป็นกล่องเปล่าสูง 430px ดูเหมือนหน้าจอพัง
   grid ยืดให้เท่ากันเองอยู่แล้ว max-height แค่กันไม่ให้ยาวเกินจอ */
.rw-col {
  padding: 10px; border-radius: 11px; max-height: min(52vh, 430px); overflow: auto;
  background: #fffdf6; border: 1px solid #e6dabb;
}
.rw-col h4 {
  margin: 0 0 8px; padding-bottom: 6px; border-bottom: 1px solid #efe4c9;
  font: 700 13px/1 var(--font-head); color: #8a6a3a;
}
.rw-empty { padding: 22px 8px; text-align: center; font-size: 12.5px; color: #9a8c70; line-height: 1.6; }

/* คอลัมน์ 1 — รายการ */
.rw-list { display: grid; gap: 5px; }
.rw-item {
  display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 7px; align-items: center;
  width: 100%; padding: 7px 8px; border-radius: 9px; cursor: pointer; text-align: left;
  background: #fffaf0; border: 1px solid #ece0c4;
}
.rw-item:hover { background: #fff7e4; }
.rw-item.on { background: #fdf0d2; border-color: #e8b64a; box-shadow: 0 0 0 2px #e8b64a55; }
.rw-item-ic { display: grid; place-items: center; font-size: 17px; }
.rw-item-tx { min-width: 0; }
.rw-item-tx b { display: block; font: 600 12.5px/1.25 var(--font-head); color: #3b3020;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rw-item-tx span { font-size: 11px; color: #8a7a5a; }
.rw-plus { font-style: normal; font-weight: 700; color: #b0791f; }
.rw-worn { font-size: 10px; color: #6b5a3a; background: #ece0c4; border-radius: 999px; padding: 2px 6px; }

/* คอลัมน์ 2 — ของที่เลือก และก่อน/หลัง */
/* ⚠️ iconFor คืน <img class="ic3d"> เมื่อมีรูปจริง และคืนอีโมจิเมื่อไม่มี
   ต้องสั่งขนาดทั้งสองแบบ ไม่งั้นรูปจริงจะเล็กจิ๋วเพราะ font-size ไม่มีผลกับ img */
.rw-big { display: grid; place-items: center; height: 116px; font-size: 76px; }
.rw-big .ic3d, .rw-big img { width: 112px; height: 112px; object-fit: contain; }
.rw-item-ic .ic3d, .rw-item-ic img { width: 24px; height: 24px; object-fit: contain; }
.rw-mat-ic .ic3d, .rw-mat-ic img { width: 30px; height: 30px; object-fit: contain; }
.rw-big-nm { text-align: center; font: 700 15px/1.3 var(--font-head); color: #3b3020; }
.rw-big-lv { text-align: center; font: 700 15px/1.4 var(--font-head); color: #b0791f; margin-bottom: 8px; }
.rw-stats, .rw-after { display: grid; gap: 3px; font-size: 12.5px; }
.rw-stats > div, .rw-after > div:not(.rw-after-t) {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px; align-items: baseline;
  padding: 3px 7px; border-radius: 7px; background: #faf4e6; color: #5b4524;
}
.rw-stats b, .rw-after b { font-weight: 700; color: #3b3020; }
.rw-after { margin-top: 9px; padding-top: 9px; border-top: 1px dashed #e0d2ab; }
.rw-after-t { font: 700 12px/1 var(--font-head); color: #2f6f73; margin-bottom: 4px; }
.rw-after > div:not(.rw-after-t) { background: #eef7ef; }
.rw-after .up { font-style: normal; font-weight: 700; color: #3d8a2a; }
.rw-after.done { padding: 14px 8px; text-align: center; color: #8a7a5a; background: none; border-top: 0; }

/* คอลัมน์ 3 — วัสดุและค่าจ้าง */
.rw-arrow {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  padding: 10px 6px; margin-bottom: 9px; border-radius: 10px;
  background: linear-gradient(#fdf3dc, #f7e7c2); border: 1px solid #e6d3a4;
  font: 700 26px/1 var(--font-head); color: #8a6a3a;
}
.rw-arrow i { font-style: normal; font-size: 18px; color: #b9a071; }
.rw-arrow .to { color: #2f6f73; }
.rw-arrow.small { font-size: 19px; padding: 6px; margin: 6px 0; }
.rw-sub { font: 700 11.5px/1 var(--font-head); color: #8a6a3a; margin: 9px 0 5px; }
.rw-mat, .rw-gold {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 9px; border-radius: 9px; background: #faf4e6; border: 1px solid #ece0c4;
}
.rw-mat-ic { font-size: 20px; }
.rw-mat-tx b { display: block; font: 600 12.5px/1.25 var(--font-head); color: #3b3020; }
.rw-mat-tx span, .rw-gold span { font-size: 11.5px; color: #8a7a5a; }
.rw-mat.none { color: #9a8c70; font-size: 12px; }
.rw-gold b { font: 700 15px/1 var(--font-head); color: #3b3020; margin-left: auto; }
.rw-gold .rw-coin { width: 17px; height: 17px; border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #ffe9a8, #e8b64a 62%, #b98a2a); }
/* ขาดอะไรต้องบอกว่าขาด ไม่ใช่แค่ทำปุ่มกดไม่ได้เงียบ ๆ */
.rw-mat.lack, .rw-gold.lack { border-color: #e2a79a; background: #fdf0ec; }
.rw-mat.lack .rw-mat-tx span, .rw-gold.lack span { color: #b8402e; font-weight: 700; }
.rw-buy {
  margin-left: auto; padding: 4px 9px; border-radius: 8px; cursor: pointer;
  border: 1px solid #b9954a; background: linear-gradient(#fff8e8, #ecd8a6);
  color: #6b5320; font: 600 11.5px/1 var(--font-head);
}
.rw-buy:hover { background: linear-gradient(#fffdf6, #f4e6bf); }
.rw-guard {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  padding: 8px 9px; border-radius: 9px; cursor: pointer;
  background: #f2f7f3; border: 1px solid #cfe0d4;
}
.rw-guard.on { background: #e6f2ec; border-color: #2f6f73; }
.rw-guard.off { opacity: .74; cursor: default; }
.rw-guard input { width: 16px; height: 16px; accent-color: #2f6f73; }
.rw-guard b { display: block; font: 600 12.5px/1.25 var(--font-head); color: #285b4a; }
.rw-guard > span { min-width: 0; }
.rw-guard i { font-style: normal; font-size: 11px; color: #4a7a63; }

/* คอลัมน์ 4 — โอกาสและความเสี่ยง */
.rw-pct { text-align: center; font: 700 46px/1 var(--font-head); }
.rw-pct small { font-size: 18px; font-weight: 400; margin-left: 2px; }
.rw-pct[data-risk="safe"] { color: #3d8a2a; }
.rw-pct[data-risk="mid"] { color: #c08a20; }
.rw-pct[data-risk="risk"] { color: #b8402e; }
.rw-meter { height: 11px; margin: 9px 0 4px; border-radius: 999px; background: #ece0c4; overflow: hidden; }
.rw-meter i { display: block; height: 100%; border-radius: 999px; }
.rw-meter[data-risk="safe"] i { background: linear-gradient(90deg, #7fc35e, #4f9c34); }
.rw-meter[data-risk="mid"] i { background: linear-gradient(90deg, #f0cf72, #d39c22); }
.rw-meter[data-risk="risk"] i { background: linear-gradient(90deg, #eaa08c, #c0503a); }
.rw-bonus { font-size: 11px; color: #2f6f73; text-align: center; }
.rw-risk { padding: 8px 9px; overflow-wrap: anywhere; border-radius: 9px; background: #fdf3ec; border: 1px solid #ecd6c4;
  font-size: 12.5px; line-height: 1.5; color: #7a4a2a; }
.rw-risk b { color: #b8402e; }
.rw-risk span { color: #8a7a5a; }
.rw-risk.guarded { background: #eef7ef; border-color: #c6e0cb; color: #2f6f4a; }
.rw-risk.guarded b { color: #2f6f4a; }
.rw-info { margin-top: 10px; padding-top: 9px; border-top: 1px dashed #e0d2ab; }
.rw-info ul { margin: 0; padding-left: 16px; font-size: 11.5px; line-height: 1.65; color: #7a6a4a; }
.rw-link { background: none; border: 0; padding: 4px 0 0; cursor: pointer;
  color: #2f6f73; font-size: 11.5px; text-decoration: underline; }
.rw-table { display: grid; gap: 3px; margin-top: 6px; }
.rw-table > div { display: grid; grid-template-columns: 34px auto minmax(0, 1fr); gap: 6px;
  padding: 3px 7px; border-radius: 6px; background: #faf4e6; font-size: 11.5px; color: #5b4524; }
.rw-table i { font-style: normal; text-align: right; color: #8a7a5a; }
.rw-table > div[data-risk="safe"] b { color: #3d8a2a; }
.rw-table > div[data-risk="mid"] b { color: #c08a20; }
.rw-table > div[data-risk="risk"] b { color: #b8402e; }

/* ── ปุ่มหลัก ────────────────────────────────────────────────────────── */
.rw-go {
  min-width: 280px; min-height: 54px; padding: 0 22px; border-radius: 13px; cursor: pointer;
  border: 1px solid #a9752a; background: linear-gradient(#ffd980, #eaa93a 62%, #d8922b);
  color: #4a3512; font: 700 17px/1 var(--font-head); text-shadow: 0 1px 0 #fff6;
  box-shadow: inset 0 1px 0 #fff8, 0 2px 5px #0002;
}
.rw-go:hover:not(:disabled) { filter: brightness(1.05); }
.rw-go:disabled { background: linear-gradient(#efe6d2, #ded2b6); border-color: #c4b48e;
  color: #9a8c70; text-shadow: none; cursor: default; box-shadow: none; }
.rw-cancel {
  min-height: 40px; padding: 0 16px; border-radius: 10px; cursor: pointer;
  border: 1px solid #c9b88e; background: #f6efdd; color: #6b5a3a; font: 600 13px/1 var(--font-head);
}
.rw-why { font-size: 12px; color: #8a7a5a; }

/* ── ยืนยันก่อนตี (เฉพาะขั้นที่มีโอกาสพลาด) ───────────────────────────── */
.rw-confirm { position: absolute; inset: 0; display: grid; place-items: center;
  background: #2b200f66; backdrop-filter: blur(1.5px); border-radius: 8px; z-index: 5; }
.rw-confirm-in { width: min(88%, 320px); padding: 16px; border-radius: 13px; text-align: center;
  background: #fffdf6; border: 1px solid #e0cda0; box-shadow: 0 8px 26px #00000033; }
.rw-confirm-in > b { font: 700 15px/1.3 var(--font-head); color: #3b3020; }
.rw-confirm-ln { font-size: 12.5px; color: #5b4524; margin-top: 4px; }
.rw-confirm-ln b[data-risk="safe"] { color: #3d8a2a; }
.rw-confirm-ln b[data-risk="mid"] { color: #c08a20; }
.rw-confirm-ln b[data-risk="risk"] { color: #b8402e; }
.rw-confirm-ln.risk { color: #b8402e; }
.rw-confirm-act { display: grid; gap: 7px; margin-top: 13px; }
.rw-confirm-act .rw-go { min-width: 0; min-height: 44px; font-size: 15px; }

/* ── ผลลัพธ์ ─────────────────────────────────────────────────────────── */
.rw-flash { position: absolute; left: 50%; top: 46%; translate: -50% -50%; z-index: 6;
  padding: 13px 26px; border-radius: 13px; font: 700 20px/1.2 var(--font-head);
  animation: rwPop .45s ease-out; pointer-events: none; }
.rw-flash.ok { background: #eaf7e6; border: 1px solid #8bbf6a; color: #2f6b22;
  box-shadow: 0 0 26px #8bbf6a66; }
.rw-flash.no { background: #fdeeea; border: 1px solid #d78a7a; color: #9c3a2a; }
@keyframes rwPop { from { opacity: 0; scale: .86; } to { opacity: 1; scale: 1; } }
@media (prefers-reduced-motion: reduce) { .rw-flash { animation: none; } }

/* ⚠️ ต้องยุบตาม "ผังสัมผัส" ไม่ใช่ตามความกว้างจอ — มือถือแนวนอน (915x412) จอกว้าง
   แต่หน้าต่างเป็นแผงข้างกว้างแค่ 493px สี่คอลัมน์จึงถูกบีบจนอ่านไม่ออก
   (เจอจริงตอนถ่ายจอ · media query ที่ดูความกว้างจอมองไม่เห็นเคสนี้เลย)
   ผังมือถือเต็มรูปแบบยังไม่ได้ทำ ตามบรีฟข้อ 20 ที่ให้ทำเดสก์ท็อปก่อน */
html.touch-ui .rw-cols { grid-template-columns: 1fr 1fr; }
html.touch-ui .rw-col { max-height: none; }
html.touch-ui .rw-head { grid-template-columns: 40px auto minmax(0, 1fr) 104px; gap: 8px; padding: 8px 10px; }
html.touch-ui .rw-crest { width: 40px; height: 40px; }   /* ตราต้องหดตามคอลัมน์ ไม่งั้นล้นไปทับชื่อ */
html.touch-ui .rw-ferra { width: 104px; height: 104px; }
html.touch-ui .rw-say { max-width: 200px; font-size: 12px; padding: 7px 10px; }
html.touch-ui .rw-title b { font-size: 16px; }
html.touch-ui .rw-go { min-width: 0; }
@media (max-width: 520px) {
  html.touch-ui .rw-cols { grid-template-columns: 1fr; }
  html.touch-ui .rw-ferra { display: none; }
  html.touch-ui .rw-head { grid-template-columns: 36px auto minmax(0, 1fr); }
  html.touch-ui .rw-crest { width: 36px; height: 36px; }
}
