/**
 * 2D Pixel Art / RPG Theme for Office Status Floor Plan
 * สไตล์เกม 2D Pixel Art: กราฟิกคมชัด สไตล์ 8-bit/16-bit
 */

/* ---------- ซ่อนองค์ประกอบ 2D เมื่อเปิดในโหมดมาตรฐาน (Classic) ---------- */
.fp-stage:not(.pixel-theme) .pixel-character-wrap,
.fp-stage:not(.pixel-theme) .rpg-popover,
.fp-stage:not(.pixel-theme) .pixel-status-bar {
  display: none !important;
}

/* ---------- โหมดธีม Pixel บนเวทีแผนผัง ---------- */
.fp-stage.pixel-theme {
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  /* พื้นหลังกระเบื้องออฟฟิศแนวเกม 16-bit หากยังไม่ได้อัปโหลดภาพพื้นหลัง */
  background-color: #cbd5e1;
  background-image: 
    linear-gradient(45deg, #e2e8f0 25%, transparent 25%), 
    linear-gradient(-45deg, #e2e8f0 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #e2e8f0 75%), 
    linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 32px 32px;
  background-position: 0 0, 0 16px, 16px -16px, -16px 0px;
  transition: background-color 0.3s ease;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.12);
}

.fp-stage.pixel-theme.has-bg {
  /* หากมีรูปภาพพื้นหลังที่อัปโหลดไว้ ให้ใช้รูปพื้นหลังเดิมพร้อมเรนเดอร์แบบ pixelated */
  background-image: inherit;
  background-size: 100% 100%;
}

/* ปรับเส้นกริดในโหมดเกม */
.fp-stage.pixel-theme .fp-grid {
  opacity: 0.15;
  background-size: 32px 32px;
}

/* รองรับโหมดจัดผังห้องของ Admin */
.fp-edit .fp-desk {
  cursor: grab !important;
}
.fp-edit .fp-desk.dragging {
  cursor: grabbing !important;
  transform: translate(-50%, -50%) scale(1.1) !important;
  z-index: 50 !important;
}
.fp-stage.pixel-theme .fp-remove {
  position: absolute;
  top: -10px;
  left: -8px;
  width: 20px;
  height: 20px;
  background: #ef4444 !important;
  color: #fff !important;
  border: 1px solid #fff !important;
  border-radius: 50% !important;
  font-size: 14px !important;
  line-height: 1 !important;
  display: flex !important;
  align-items: center;
  justify-content: center;
  cursor: pointer !important;
  z-index: 30 !important;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3) !important;
  padding: 0 !important;
}
.fp-stage.pixel-theme .fp-remove:hover {
  background: #dc2626 !important;
  transform: scale(1.15) !important;
}

/* ---------- กล่องโต๊ะและตัวละครในโหมดเกม ---------- */
.fp-stage.pixel-theme .fp-desk {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  width: auto !important;
  min-width: 64px !important;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  z-index: 5;
  transition: transform 0.15s ease;
}

.fp-stage.pixel-theme .fp-desk:hover {
  transform: translate(-50%, -54%) scale(1.06);
  z-index: 20;
}

/* ซ่อนแถบและไอคอนมาตรฐานในโหมด Pixel */
.fp-stage.pixel-theme .fp-desk-top,
.fp-stage.pixel-theme .fp-tag,
.fp-stage.pixel-theme .fp-role,
.fp-stage.pixel-theme .fp-detail {
  display: none !important;
}

/* ตัวละคร Sprite */
.fp-stage.pixel-theme .pixel-character-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: pixel-idle 2.4s ease-in-out infinite;
}

.fp-stage.pixel-theme .pixel-sprite {
  width: 52px;
  height: 52px;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.35));
}

/* บอลลูนสถานะเหนือหัว */
.pixel-balloon {
  position: absolute;
  top: -18px;
  right: -8px;
  background: #ffffff;
  border: 2px solid #1e293b;
  border-radius: 6px;
  padding: 2px 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  animation: balloon-float 2s ease-in-out infinite alternate;
  z-index: 10;
}

/* บอลลูนนอนหลับ Zzz */
.pixel-balloon.balloon-leave {
  background: #fef08a;
  border-color: #854d0e;
}

.pixel-balloon.balloon-leave .z-char {
  font-family: 'Courier New', monospace, sans-serif;
  font-weight: 900;
  color: #a16207;
  line-height: 1;
  display: inline-block;
}

.pixel-balloon.balloon-leave .z-1 { font-size: 9px; }
.pixel-balloon.balloon-leave .z-2 { font-size: 11px; margin-left: -1px; }
.pixel-balloon.balloon-leave .z-3 { font-size: 13px; margin-left: -1px; }

/* บอลลูนไปราชการ */
.pixel-balloon.balloon-offsite {
  background: #e0f2fe;
  border-color: #0369a1;
}

/* บอลลูนมาปฏิบัติงาน */
.pixel-balloon.balloon-office {
  background: #f0fdf4;
  border-color: #15803d;
}

/* ป้ายชื่อสไตล์เกมใต้โต๊ะ */
.fp-stage.pixel-theme .fp-name {
  margin-top: 2px !important;
  padding: 2px 6px !important;
  background: rgba(15, 23, 42, 0.88) !important;
  color: #f8fafc !important;
  border: 1px solid rgba(255, 255, 255, 0.3) !important;
  border-radius: 4px !important;
  font-size: 0.72rem !important;
  font-weight: 600 !important;
  white-space: nowrap !important;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35) !important;
  text-shadow: 0 1px 2px #000;
  transition: background 0.15s ease;
}

.fp-stage.pixel-theme .fp-desk:hover .fp-name {
  background: #1e293b !important;
  border-color: #38bdf8 !important;
  color: #38bdf8 !important;
}

.fp-stage.pixel-theme .fp-desk.is-exec .fp-name {
  border-color: #facc15 !important;
  color: #fef08a !important;
}

/* แถบไฟสถานะใต้ป้ายชื่อ */
.pixel-status-bar {
  width: 24px;
  height: 4px;
  border-radius: 2px;
  margin-top: 2px;
  border: 1px solid rgba(0, 0, 0, 0.3);
}
.status-bar-office { background-color: #22c55e; box-shadow: 0 0 6px #22c55e; }
.status-bar-offsite { background-color: #f59e0b; box-shadow: 0 0 6px #f59e0b; }
.status-bar-leave { background-color: #ef4444; box-shadow: 0 0 6px #ef4444; }

/* ---------- แอนิเมชันสไตล์เกม ---------- */
@keyframes pixel-idle {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

@keyframes balloon-float {
  0% { transform: translateY(0); }
  100% { transform: translateY(-4px); }
}

/* ---------- RPG Dialogue Card (กล่องข้อมูลเมื่อคลิก/Hover โต๊ะ) ---------- */
.rpg-popover {
  position: absolute;
  bottom: calc(100% + 14px);
  left: 50%;
  transform: translateX(-50%);
  width: 230px;
  background: #0f172a;
  border: 2px solid #f8fafc;
  outline: 2px solid #0f172a;
  border-radius: 6px;
  padding: 10px;
  color: #f8fafc;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  font-family: inherit;
  z-index: 100;
  display: none;
  pointer-events: auto;
}

.rpg-popover::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -6px;
  border-width: 6px;
  border-style: solid;
  border-color: #0f172a transparent transparent transparent;
}

.fp-stage.pixel-theme .fp-desk:hover .rpg-popover,
.fp-stage.pixel-theme .fp-desk:focus-within .rpg-popover {
  display: block;
  animation: rpg-fade-in 0.15s ease-out;
}

@keyframes rpg-fade-in {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.rpg-popover-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.2);
  padding-bottom: 6px;
}

.rpg-portrait {
  width: 36px;
  height: 36px;
  background: #1e293b;
  border: 1px solid #64748b;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.rpg-title {
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.2;
}

.rpg-badge {
  font-size: 0.68rem;
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 600;
  display: inline-block;
  margin-top: 3px;
}

.rpg-badge-office { background: #166534; color: #bbf7d0; border: 1px solid #22c55e; }
.rpg-badge-offsite { background: #854d0e; color: #fef08a; border: 1px solid #eab308; }
.rpg-badge-leave { background: #991b1b; color: #fecaca; border: 1px solid #ef4444; }

.rpg-body {
  font-size: 0.73rem;
  color: #cbd5e1;
  line-height: 1.35;
}

.rpg-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 3px 0;
  background: #2563eb;
  color: #ffffff;
  border: 1px solid #60a5fa;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease;
}

.rpg-btn:hover {
  background: #1d4ed8;
  color: #ffffff;
}

/* ---------- ปุ่มสลับโหมดและเสียงในส่วนหัว ---------- */
.theme-switch-btn {
  display: inline-flex;
  align-items: center;
  font-size: 0.82rem;
  font-weight: 600;
}

/* ---------- ตัวละครเดินในห้อง (Ambient Walking) ---------- */
.pixel-walker {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
  cursor: pointer;
}

.pixel-walker .walker-body {
  transition: transform 0.2s ease;
}

.pixel-walker.walking .walker-body {
  animation: walker-wobble 0.35s ease-in-out infinite alternate;
}

@keyframes walker-wobble {
  0% { transform: translateY(0) rotate(-3deg); }
  100% { transform: translateY(-4px) rotate(3deg); }
}

.walker-balloon {
  position: absolute;
  top: -22px;
  background: #ffffff;
  border: 2px solid #0f172a;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
  animation: balloon-float 1.5s ease-in-out infinite alternate;
  z-index: 50;
}

.walker-name {
  font-size: 0.68rem;
  background: rgba(15, 23, 42, 0.85);
  color: #f8fafc;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.25);
  white-space: nowrap;
  margin-top: 2px;
  text-shadow: 0 1px 2px #000;
}

.pixel-walker:hover .rpg-popover {
  display: block;
  animation: rpg-fade-in 0.15s ease-out;
}

/* เมื่อเจ้าของโต๊ะลุกเดิน ให้จางตัวละครที่โต๊ะ */
.fp-stage.pixel-theme .fp-desk.is-away .pixel-character-wrap {
  opacity: 0.2;
  filter: grayscale(80%);
}
.fp-stage.pixel-theme .fp-desk.is-away::after {
  content: 'ไม่อยู่ที่โต๊ะ';
  position: absolute;
  top: -16px;
  font-size: 0.62rem;
  background: rgba(100, 116, 139, 0.85);
  color: #fff;
  padding: 1px 4px;
  border-radius: 3px;
  white-space: nowrap;
}

/* ---------- Office Landmarks (ฉากจำลองห้องทำงาน) ---------- */
.fp-landmark {
  position: absolute;
  transform: translate(-50%, -50%);
  display: none; /* ซ่อนในโหมดมาตรฐานของหน้าบ้าน */
  z-index: 5;
  user-select: none;
  pointer-events: none;
}

.fp-stage.pixel-theme .fp-landmark {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.fp-landmark .lm-icon {
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.25));
}

.fp-landmark .lm-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: #475569;
  background: rgba(255, 255, 255, 0.7);
  padding: 0 4px;
  border-radius: 3px;
  margin-top: 2px;
  white-space: nowrap;
}

/* Landmark ในโหมดแก้ไขของ Admin (แสดงผลเสมอและเปิด pointer-events ให้คลิกลากได้) */
.fp-edit .fp-landmark,
.fp-landmark.is-draggable {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  cursor: grab !important;
  pointer-events: auto !important;
  z-index: 35 !important;
  user-select: none !important;
  touch-action: none !important;
  padding: 4px 6px;
  border: 2px dashed #2563eb !important;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88) !important;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.fp-edit .fp-landmark:hover,
.fp-landmark.is-draggable:hover {
  border-color: #1d4ed8 !important;
  background: #ffffff !important;
  transform: translate(-50%, -50%) scale(1.1) !important;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.35) !important;
  z-index: 45 !important;
}

.fp-edit .fp-landmark.dragging,
.fp-landmark.is-draggable.dragging {
  cursor: grabbing !important;
  border-color: #ef4444 !important;
  background: #fef2f2 !important;
  transform: translate(-50%, -50%) scale(1.18) !important;
  z-index: 70 !important;
  box-shadow: 0 10px 25px rgba(239, 68, 68, 0.4) !important;
}

.fp-landmark.is-draggable * {
  pointer-events: none;
}
