/* =====================================================
   MODULE CSS: USER FORM CONFIG (ISOLATED)
===================================================== */

/* Kiềm tỏa khung Wrapper bám khít theo chiều cao overlay hệ thống */
.form-overlay-wrapper {
  background: #ffffff;
  width: 100%;
  max-width: 900px;
  height: 100vh;           /* Khóa cứng chiều cao bằng viewport tránh tràn/lệch view */
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.1);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  box-sizing: border-box;
}

/* Header cố định lên đỉnh đầu form */
.form-overlay-header {
  padding: 16px 24px;
  border-bottom: 1px solid #eef2f5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: #ffffff;    /* Đảm bảo che phần nội dung khi cuộn lên */
  z-index: 10;
}

.form-overlay-header h2 {
  margin: 0;
  font-size: 1.3rem;
  color: #2d3748;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* 🔥 TRỌNG TÂM: Biến vùng body thành khu vực cuộn độc lập, loại bỏ double scrollbar */
.form-overlay-body {
  padding: 24px;
  flex: 1;
  overflow-y: auto;        /* Kích hoạt thanh cuộn nội bộ mượt mà */
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-sizing: border-box;
}

/* --- Hệ thống Grid Thông Minh --- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.employee-info-subgrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  background: #f8fafc;
  padding: 16px;
  border-radius: 6px;
  border: 1px dashed #cbd5e1;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #4a5568;
  margin-bottom: 6px;
}

/* --- Form Controls Đồng Bộ (Bao gồm cả select/input sinh ra từ Select.js) --- */
.form-control, 
.form-grid select, 
.form-grid input[type="text"], 
.form-grid input[type="email"],
.kn-grid select,
.kn-grid input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #cbd5e0;
  border-radius: 4px;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  box-sizing: border-box;
  background-color: #ffffff;
}

.form-control:focus, .form-grid select:focus {
  border-color: #3182ce;
  outline: none;
  box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.15);
}

.form-control:disabled, .form-grid select:disabled, .form-grid input:disabled {
  background-color: #edf2f7;
  color: #718096;
  cursor: not-allowed;
}

/* --- Custom Checkbox & Tiện ích căn lề --- */
.flex-align-center {
  display: flex;
  align-items: center;
  padding-top: 26px; /* Cân bằng baseline hoàn hảo với các ô có label song song */
}

.checkbox-container {
  display: flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
  font-size: 0.9rem;
}

.checkbox-container input {
  margin-right: 8px;
  width: 16px;
  height: 16px;
}

.section-divider {
  margin: 4px 0;
  border: 0;
  border-top: 1px solid #e2e8f0;
}

/* --- Section Kiêm Nhiệm --- */
.kiem-nhiem-section {
  background: #f7fafc;
  padding: 16px;
  border-radius: 6px;
  border: 1px dashed #cbd5e0;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.section-header h3 {
  margin: 0;
  font-size: 1.05rem;
  color: #4a5568;
}

.kn-list-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.kn-row {
  background: #ffffff;
  padding: 12px;
  border-radius: 4px;
  border: 1px solid #e2e8f0;
}

.kn-grid {
  display: grid;
  grid-template-columns: 2fr 2fr 1fr auto;
  gap: 12px;
  align-items: center;
}

.btn-kn-action {
  padding-top: 22px;
}

/* --- Trạng thái Badges --- */
.badge-mode {
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: bold;
}
.mode-add { background: #e3f2fd; color: #0d47a1; }
.mode-edit { background: #fff3e0; color: #e65100; }
.mode-detail { background: #f5f5f5; color: #424242; }

/* --- Cụm Buttons cố định đáy form --- */
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: auto;        /* Đẩy cụm nút xuống đáy nếu form ít data */
  padding-top: 16px;
  border-top: 1px solid #eef2f5;
  background: #ffffff;
}

.form-actions button {
  padding: 8px 20px;
  border-radius: 4px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
}

.btn-primary { background: #3182ce; color: white; }
.btn-primary:hover { background: #2b6cb0; }
.btn-secondary { background: #e2e8f0; color: #4a5568; }
.btn-secondary:hover { background: #cbd5e0; }
.btn-warning { background: #dd6b20; color: white; }
.btn-warning:hover { background: #c05621; }
.btn-danger { background: #e53e3e; color: white; padding: 6px 12px; border-radius: 4px; border: none; cursor: pointer;}
.btn-danger:hover { background: #c53030; }
.btn-circle-add { background: #319795; color: white; border: none; padding: 6px 12px; border-radius: 4px; cursor: pointer; font-weight: 500; }
.btn-circle-add:hover { background: #2c7a7b; }

/* --- Utilities --- */
.full-width { grid-column: 1 / -1; }
.hidden { display: none !important; }
.animate-fade { animation: fadeIn 0.25s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- 📱 Mobile Reponsive nội bộ cho Form --- */
@media (max-width: 768px) {
  .form-grid, .employee-info-subgrid, .kn-grid {
    grid-template-columns: 1fr !important;
  }
  .btn-kn-action { padding-top: 0; }
  .flex-align-center { padding-top: 10px; }
  
  /* Đóng form hành động co giãn đều trên Mobile */
  .form-actions {
    justify-content: stretch;
  }
  .form-actions button {
    flex: 1;
    text-align: center;
  }
}