/* ===================================================================
   calculator.css — สไตล์เฉพาะหน้าเครื่องคำนวณค่าสถานะ
   ใช้ตัวแปรสี/ฟอนต์ร่วมกับ style.css (โหลด style.css ไว้ก่อนไฟล์นี้เสมอ)
   =================================================================== */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* บังคับให้ attribute "hidden" มีผลเสมอ แม้ element นั้นจะตั้ง display เอง
   (ถ้าไม่มีบรรทัดนี้ ช่อง "จำนวนที่ใส่" และปุ่มลบจะโผล่ค้างแม้ตั้ง hidden ไว้แล้ว) */
[hidden] { display: none !important; }

/* ---------- แถบสรุปผลแบบย่อ ติดด้านบนตลอดเวลา (sticky) ---------- */
.calc-summary-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  background: var(--ink-900);
  border: 1px solid var(--ink-700);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  margin: var(--space-3) 0;
}

.calc-summary-bar-empty {
  margin: 0;
  color: var(--parchment-dim);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.calc-summary-bar-stats,
.calc-summary-bar-combos {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.calc-summary-bar-combos {
  padding-left: 0.5rem;
  border-left: 1px solid var(--ink-700);
}

.calc-summary-bar-chip {
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-radius: 999px;
  padding: 0.28rem 0.65rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--parchment-dim);
  white-space: nowrap;
}
.calc-summary-bar-chip strong {
  color: var(--gold);
  margin-left: 0.3rem;
}

.calc-summary-bar-combo-chip {
  background: rgba(91, 140, 114, 0.15);
  border: 1px solid var(--moss);
  border-radius: 999px;
  padding: 0.28rem 0.65rem;
  font-family: var(--font-body);
  font-size: 0.72rem;
  color: var(--parchment);
  white-space: nowrap;
}

/* ---------- โครงหลัก: ซ้าย = ช่องเลือกทั้งหมด / ขวา = แผงเลือกรายการ ---------- */
.calc-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 1fr);
  gap: var(--space-3);
  align-items: start;
  margin: var(--space-4) 0;
}

/* ---------- ซ้าย: ช่องอุปกรณ์ทั้งหมด ขนาดเท่ากัน ช่องการ์ดอยู่ใต้ช่องอุปกรณ์ของตัวเอง ---------- */
.calc-slots-panel {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 0.6rem;
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-radius: var(--radius);
  padding: var(--space-3);
  align-content: start;
  align-items: start;
}

/* กล่องรวมของแต่ละช่อง = ช่องอุปกรณ์ (สี่เหลี่ยม) + ป้ายการ์ด (แถบเล็ก) อยู่ใต้กัน */
.calc-slot-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.calc-slotbox {
  position: relative;
  aspect-ratio: 1 / 1;
  width: 100%;
  background: var(--ink-900);
  border: 1px dashed var(--ink-700);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.4rem;
  cursor: pointer;
  color: var(--parchment);
  font-family: var(--font-body);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.calc-slotbox:hover { border-color: var(--gold); }
.calc-slotbox.is-filled { border-style: solid; border-color: var(--moss); }
.calc-slotbox.is-active { border-color: var(--gold); border-style: solid; background: rgba(212, 175, 55, 0.08); }

.calc-slotbox-kind {
  position: absolute;
  top: 4px;
  left: 4px;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.02em;
  color: var(--parchment-dim);
  background: rgba(0, 0, 0, 0.35);
  border-radius: 4px;
  padding: 1px 4px;
}

.calc-slotbox-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--rust);
  color: var(--ink-900);
  border: none;
  font-size: 0.85rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
}
.calc-slotbox-remove:hover { filter: brightness(1.1); }

.calc-slotbox-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--ink-700);
  border: 1px solid var(--ink-700);
  flex-shrink: 0;
}
.calc-slotbox-icon img { width: 100%; height: 100%; object-fit: cover; }

.calc-slotbox-label {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--gold);
  font-size: 0.72rem;
  line-height: 1.2;
  text-align: center;
}

.calc-slotbox-value {
  font-size: 0.66rem;
  color: var(--parchment-dim);
  text-align: center;
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- ป้ายเลือกการ์ด (แถบเล็กใต้ช่องอุปกรณ์) ---------- */
.calc-cardtag {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  background: rgba(212, 175, 55, 0.07);
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  color: var(--parchment);
  font-family: var(--font-body);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.calc-cardtag:hover { background: rgba(212, 175, 55, 0.14); }
.calc-cardtag.is-filled { border-color: var(--moss); background: rgba(91, 140, 114, 0.12); }
.calc-cardtag.is-active { box-shadow: 0 0 0 1px var(--gold) inset; }

.calc-cardtag-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border-radius: 4px;
  overflow: hidden;
  background: var(--ink-700);
}
.calc-cardtag-icon img { width: 100%; height: 100%; object-fit: contain; }

.calc-cardtag-text {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.7rem;
  line-height: 1.2;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calc-cardtag-remove {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--rust);
  color: var(--ink-900);
  font-size: 0.68rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.calc-cardtag-remove:hover { filter: brightness(1.1); }

/* ---------- ขวา: แผงเลือกรายการ (แทน popup เดิม) ---------- */
.calc-picker-panel {
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-radius: var(--radius);
  padding: var(--space-3);
  min-height: 320px;
  position: sticky;
  top: var(--space-3);
  display: flex;
  flex-direction: column;
}

.calc-picker-empty {
  margin: auto;
  color: var(--parchment-dim);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-align: center;
}

.calc-picker-content {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-height: 0;
}

.calc-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}
.calc-picker-head h3 { margin: 0; font-size: 1.05rem; }

.calc-picker-clear {
  background: none;
  border: 1px solid var(--rust);
  color: var(--rust);
  border-radius: var(--radius);
  padding: 0.3rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  cursor: pointer;
  flex-shrink: 0;
}
.calc-picker-clear:hover { background: rgba(180, 80, 60, 0.12); }

.calc-picker-search input {
  width: 100%;
  padding: 0.5rem 0.7rem;
  background: var(--ink-900);
  border: 1px solid var(--ink-700);
  border-radius: var(--radius);
  color: var(--parchment);
  font-family: var(--font-body);
}

.calc-picker-list {
  overflow-y: auto;
  max-height: 52vh;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 0.5rem;
  padding-right: 2px;
}

.calc-picker-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  background: var(--ink-900);
  border: 1px solid var(--ink-700);
  border-radius: var(--radius);
  padding: 0.5rem 0.4rem;
  cursor: pointer;
  text-align: center;
  color: var(--parchment);
  font-family: var(--font-body);
}
.calc-picker-option:hover { border-color: var(--gold); }
.calc-picker-option.is-selected { border-color: var(--moss); background: rgba(91, 140, 114, 0.15); }

.calc-picker-option img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--ink-700);
}
.calc-picker-option-name {
  font-size: 0.76rem;
  line-height: 1.2;
}
.calc-picker-option-stats {
  color: var(--parchment-dim);
  font-family: var(--font-mono);
  font-size: 0.66rem;
  line-height: 1.3;
}

.calc-picker-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--ink-700);
  flex-shrink: 0;
}
.calc-picker-footer label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--parchment-dim);
}
.calc-picker-footer input[type="number"] {
  width: 70px;
  padding: 0.35rem 0.5rem;
  background: var(--ink-900);
  border: 1px solid var(--ink-700);
  border-radius: var(--radius);
  color: var(--parchment);
}
.calc-btn-confirm {
  background: var(--gold);
  color: var(--ink-900);
  border: none;
  border-radius: var(--radius);
  padding: 0.5rem 1.1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
}
.calc-btn-confirm:hover { filter: brightness(1.08); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .calc-workspace { grid-template-columns: 1fr; }
  .calc-picker-panel { position: static; min-height: 0; }
}

@media (max-width: 600px) {
  .calc-slots-panel { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
  .calc-picker-list { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
}
