/* --- 1. Tree Layout & Scrolling --- */
.tree-wrapper {
  width: 100%;
  height: 600px;
  overflow: auto;
  padding: 40px;
  background-color: #f8f9fa;
  background-image: radial-gradient(#e0e0e0 1px, transparent 1px);
  background-size: 20px 20px;
  cursor: grab;
  user-select: none;
  text-align: center;
}
.tree-wrapper:active {
  cursor: grabbing;
}

#tree-container {
  transform-origin: center top;
  transition: transform 0.3s ease;
  display: inline-block;
  min-width: 100%;
  padding-bottom: 100px;
}
.tree {
  display: table;
  margin: 0 auto;
}

/* --- 2. Fullscreen Mode --- */
.card.fullscreen-mode {
  position: fixed !important;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 99999;
  border-radius: 0;
  margin: 0;
}
.card.fullscreen-mode .card-body {
  height: calc(100vh - 70px);
}
.card.fullscreen-mode .tree-wrapper {
  height: 100% !important;
  border: none;
}

/* --- 3. Node Styles --- */
.tree ul,
.tree li {
  list-style-type: none !important;
  margin: 0 !important;
  padding: 0 !important;
  position: relative !important;
}
.tree ul {
  padding-top: 20px !important;
  display: flex !important;
  justify-content: center !important;
  transition: all 0.5s !important;
}
.tree li {
  float: left !important;
  text-align: center !important;
  padding: 20px 5px 0 5px !important;
  transition: all 0.5s !important;
}

/* Connectors */
.tree li::before,
.tree li::after {
  content: "" !important;
  position: absolute !important;
  top: 0 !important;
  right: 50% !important;
  border-top: 2px solid #000 !important;
  width: 50% !important;
  height: 20px !important;
  z-index: 0 !important;
}
.tree li::after {
  right: auto !important;
  left: 50% !important;
  border-left: 2px solid #000 !important;
}
.tree ul ul::before {
  content: "" !important;
  position: absolute !important;
  top: 0 !important;
  left: 50% !important;
  border-left: 2px solid #000 !important;
  width: 0 !important;
  height: 20px !important;
  transform: translateX(-50%) !important;
  z-index: 0 !important;
}
.tree li:only-child::after,
.tree li:only-child::before {
  display: none !important;
}
.tree li:only-child {
  padding-top: 0 !important;
}
.tree li:first-child::before,
.tree li:last-child::after {
  border: 0 none !important;
}
.tree li:last-child::before {
  border-right: 2px solid #000 !important;
  border-radius: 0 5px 0 0 !important;
}
.tree li:first-child::after {
  border-radius: 5px 0 0 0 !important;
}

/* --- 4. Node Content Box --- */
.node-content {
  border: 2px solid #ccc;
  padding: 10px;
  text-decoration: none;
  color: #444;
  font-family: "Sarabun", sans-serif;
  font-size: 14px;
  display: inline-block;
  border-radius: 12px;
  transition: all 0.3s;
  background: white;
  min-width: 160px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 10 !important;
}
.node-content:hover {
  box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
  transform: translateY(-2px);
  z-index: 20 !important;
}

/* Profile Image */
.node-img-wrapper {
  width: 60px;
  height: 60px;
  margin: 0 auto 5px auto;
}
.node-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
  background-color: #eee;
}

.node-name {
  font-weight: bold;
  display: block;
  margin-bottom: 2px;
  font-size: 1.05em;
  line-height: 1.2;
}
.node-role {
  font-size: 0.85em;
  color: #666;
  display: block;
}

/* Colors */
.root-node {
  background: #003366 !important;
  color: white !important;
  border: 2px solid #003366 !important;
}
.root-node .node-role {
  color: #ddd !important;
}
.color-red {
  background: #ffebee !important;
  border-color: #f44336 !important;
  border-bottom-width: 3px !important;
}
.color-orange {
  background: #fff3e0 !important;
  border-color: #ff9800 !important;
  border-bottom-width: 3px !important;
}
.color-yellow {
  background: #fffde7 !important;
  border-color: #ffc107 !important;
  border-bottom-width: 3px !important;
}
.color-green {
  background: #e8f5e9 !important;
  border-color: #4caf50 !important;
  border-bottom-width: 3px !important;
}
.color-blue {
  background: #e3f2fd !important;
  border-color: #2196f3 !important;
  border-bottom-width: 3px !important;
}
.color-purple {
  background: #f3e5f5 !important;
  border-color: #9c27b0 !important;
  border-bottom-width: 3px !important;
}
.color-pink {
  background: #fce4ec !important;
  border-color: #e91e63 !important;
  border-bottom-width: 3px !important;
}

/* Child Colors */
.color-red-child {
  background: #fff5f5 !important;
  border: 2px solid #ef5350 !important;
}
.color-orange-child {
  background: #fffaf5 !important;
  border: 2px solid #ffa726 !important;
}
.color-yellow-child {
  background: #fffef5 !important;
  border: 2px solid #ffd54f !important;
}
.color-green-child {
  background: #f1f8f4 !important;
  border: 2px solid #66bb6a !important;
}
.color-blue-child {
  background: #f0f7ff !important;
  border: 2px solid #42a5f5 !important;
}
.color-purple-child {
  background: #faf5fb !important;
  border: 2px solid #ab47bc !important;
}
.color-pink-child {
  background: #fff0f5 !important;
  border: 2px solid #ec407a !important;
}

/* Controls */
.node-tools {
  display: none;
  position: absolute;
  top: -12px;
  right: -10px;
  background: white;
  border-radius: 20px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  padding: 3px;
  z-index: 100;
}
.node-content:hover .node-tools {
  display: flex;
  gap: 3px;
}
.tool-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  color: white;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-add {
  background: #28a745;
}
.btn-edit {
  background: #ffc107;
  color: #333;
}
.btn-delete {
  background: #dc3545;
}

#zoom-controls {
  position: absolute;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
#zoom-controls button {
  width: 40px;
  height: 40px;
  background: white;
  border: 1px solid #ccc;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  transition: 0.2s;
}
#zoom-controls button:hover {
  background-color: #ffc107;
}

/* Responsive */
@media (max-width: 768px) {
  .node-content {
    min-width: 120px;
    padding: 10px 5px;
    font-size: 12px;
  }
  .node-img-wrapper {
    width: 45px;
    height: 45px;
    margin-bottom: 5px;
  }
  .node-name {
    font-size: 12px;
    white-space: normal;
  }
  .node-role {
    font-size: 10px;
  }
  .tree li {
    padding: 20px 2px 0 2px !important;
  }
  .tree-wrapper {
    height: 500px;
  }
}

/* ========================================= */
/* [NEW] Custom SweetAlert Form Styles      */
/* ส่วนที่เพิ่มใหม่สำหรับการจัดฟอร์มให้สวยงาม */
/* ========================================= */
.swal-form-container {
  text-align: left;
  padding: 0 5px;
  margin-top: 10px;
}

.swal-form-group {
  margin-bottom: 20px;
}

.swal-label {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  color: #495057;
  margin-bottom: 8px;
  text-align: left;
}

.swal-label i {
  color: #ffc107;
  margin-right: 8px;
  width: 20px;
  text-align: center;
}

.swal-input-custom {
  display: block;
  width: 100% !important;
  height: 45px;
  padding: 0.375rem 0.75rem;
  font-size: 1rem;
  color: #495057;
  background-color: #fff;
  border: 1px solid #ced4da;
  border-radius: 0.25rem;
  box-sizing: border-box;
  margin: 0 !important;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.swal-input-custom:focus {
  border-color: #ffc107;
  outline: 0;
  box-shadow: 0 0 0 0.2rem rgba(255, 193, 7, 0.25);
}

/* Custom Select Arrow */
select.swal-input-custom {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 4 5'%3E%3Cpath fill='%23343a40' d='M2 0L0 2h4zm0 5L0 3h4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 8px 10px;
  padding-right: 2rem;
}

/* --- Fix iOS Flickering --- */
#tree-container,
.node-content {
  /* 1. บังคับใช้ GPU เร่งการแสดงผล */
  -webkit-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);

  /* 2. ป้องกันภาพเบลอหรือกระพริบตอน Zoom */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;

  /* 3. บอก Browser ล่วงหน้าว่าจะมีการขยับหรือขยาย */
  will-change: transform;

  /* 4. ป้องกันการเลือกข้อความโดยไม่ตั้งใจบน iOS */
  -webkit-user-select: none;
}

/* เพิ่มความสมูทให้ Wrapper */
.tree-wrapper {
  -webkit-overflow-scrolling: touch; /* ให้เลื่อนลื่นๆ แบบ Native iOS */
}
